section.begin
   Name = OnLanEvent
   Code : struct.begin
      [*] = ;var cAllowDebug : Boolean = False;
      [*] = ;
      [*] = ;procedure LogEvent(msg : String);
      [*] = ;begin
      [*] = ;   if (cAllowDebug) then
      [*] = ;   begin
      [*] = ;      var text : String;
      [*] = ;      text := msg+' gLanEvent='+IntToStr(gLanEvent);
      [*] = ;      if (LanPublicServerGetRegIDFrom<>0) then
      [*] = ;      text := text+' regIDFrom='+IntToStr(LanPublicServerGetRegIDFrom);
      [*] = ;      if (LanPublicServerGetRegIDTo<>0) then
      [*] = ;      text := text+' regIDTo='+IntToStr(LanPublicServerGetRegIDTo);
      [*] = ;
      [*] = ;      var tag : Integer = GetIntValueByName('Tag');
      [*] = ;      var index : Integer = LanGetClientIndexByID(tag);
      [*] = ;
      [*] = ;      if (tag<>0) or (index<>-1) then
      [*] = ;      text := text+' tag='+IntToStr(tag)+' index='+IntToStr(index);
      [*] = ;
      [*] = ;      log(text);
      [*] = ;   end;
      [*] = ;end;
      [*] = ;
      [*] = ;procedure OnTerminateGame;
      [*] = ;begin
      [*] = ;   gLanHostID := 0;
      [*] = ;   gInternetShell.ClearCurrentSession;
      [*] = ;   gInternetShell.currentsessionid := 0;
      [*] = ;   _gui_SendTagToState('EventCustomGame', gc_gui_event_tagHide);
      [*] = ;   _gui_SendTagToState('EventHistoricalBattle', gc_gui_event_tagHide);
      [*] = ;   gInternetShell.bratingroom := False;
      [*] = ;   gInternetShell.bshowroom := False;
      [*] = ;   gInternetShell.bhistoricalbattle := False;
      [*] = ;   //if (not gInternetShell.bautosearch) then
      [*] = ;   //gInternetShell.bshowranking := False;
      [*] = ;   gint_gui_updateclientlist := (1 shl 0);
      [*] = ;   gbool_gui_showinternetshell := True;
      [*] = ;   gbool_gui_setshellchatinputfocused := True;
      [*] = ;   LogEvent('OnTerminateGame');
      [*] = ;end;
      [*] = ;
      [*] = ;procedure OnConnect;
      [*] = ;begin
      [*] = ;   LogEvent('OnConnect');
      [*] = ;   var idTo : Integer = LanPublicServerGetRegIDTo;
      [*] = ;   var idFrom : Integer = LanPublicServerGetRegIDFrom;
      [*] = ;   var tag : Integer = GetIntValueByName('Tag');
      [*] = ;   LanPublicServerUpdateClientInfo(tag);
      [*] = ;   if (tag=LanMyInfoID) then
      [*] = ;   begin
      [*] = ;      if (_net_IsServer) then
      [*] = ;      begin
      [*] = ;         gLanHostID := LanMyInfoID;
      [*] = ;         gInternetShell.currentsessionid := LanMyInfoID;
      [*] = ;         Log('OnConnect : gInternetShell.currentsessionid = '+IntToStr(gInternetShell.currentsessionid));
      [*] = ;      end
      [*] = ;      else
      [*] = ;      if gInternetShell.currentsessionid>0 then
      [*] = ;      gLanHostID := gInternetShell.currentsessionid
      [*] = ;      else
      [*] = ;      begin
      [*] = ;         gInternetShell.currentsessionid := idTo;
      [*] = ;         gLanHostID := gInternetShell.currentsessionid;
      [*] = ;      end;
      [*] = ;      Log('OnConnect : gLanHostID := '+IntToStr(gLanHostID));
      [*] = ;      if (gInternetShell.bratingroom) then
      [*] = ;      begin
      [*] = ;         var team : Integer = _misc_GetClLanTeamByLanID(LanMyInfoID);
      [*] = ;         LanClSetMyTeam(team);
      [*] = ;         Log('OnConnect : LanClSetMyTeam : lanid='+IntToStr(LanMyInfoID)+' team='+IntToStr(team));
      [*] = ;      end
      [*] = ;      else
      [*] = ;      if (gInternetShell.bautosearch) then
      [*] = ;      begin
      [*] = ;         if (gInternetShell.autosearchteam=1) or (gInternetShell.autosearchteam=2) then
      [*] = ;         begin
      [*] = ;            LanClSetMyTeam(gInternetShell.autosearchteam);
      [*] = ;            Log('OnConnect : LanClSetMyTeam : gInternetShell.bautosearch : lanid='+IntToStr(LanMyInfoID)+' team='+IntToStr(gInternetShell.autosearchteam));
      [*] = ;         end;
      [*] = ;      end
      [*] = ;      else
      [*] = ;      begin
      [*] = ;         gbool_gui_updatecurrentsessionname := True;
      [*] = ;         gbool_gui_refreshcurrentsession := True;
      [*] = ;      end;
      [*] = ;      gint_gui_updatesessionlist := (1 shl 0);
      [*] = ;      if gInternetShell.bhistoricalbattle then
      [*] = ;      gMap.bbattle := True;
      [*] = ;      if (gInternetShell.bshowroom) then
      [*] = ;      begin
      [*] = ;         if (gInternetShell.bhistoricalbattle) then
      [*] = ;         gbool_gui_showhistoricalbattle := True
      [*] = ;         else
      [*] = ;         gbool_gui_showcustomgame := True;
      [*] = ;      end;
      [*] = ;      var checksumres : Integer;
      [*] = ;      if gstring_roomchecksum<>'' then
      [*] = ;      checksumres := _misc_RoomChecksumCompatible(gstring_roomchecksum)
      [*] = ;      else
      [*] = ;      checksumres := gc_result_roomchecksum_nomod;
      [*] = ;      if (checksumres=gc_result_roomchecksum_modneedsync) or (checksumres=gc_result_roomchecksum_nomoddifchecksum) then
      [*] = ;      begin
      [*] = ;         gbool_modsyncparserwait := True;
      [*] = ;         gfloat_modsyncparserwaittime := _misc_GetRealTime;
      [*] = ;         var pLan : Integer = _parser_ParserEmpty;
      [*] = ;         StringRegister7 := gstring_roomchecksum;
      [*] = ;         LanPublicServerSendSessionParser(gLanHostID, gc_LAN_MODS_MODSYNC_REQUEST, pLan);
      [*] = ;      end;
      [*] = ;   end
      [*] = ;   else
      [*] = ;   if (tag<>LanMyInfoID) then
      [*] = ;   begin
      [*] = ;      if (_net_IsServer) then
      [*] = ;      begin
      [*] = ;         //log('I am server and someone joined my room.');
      [*] = ;         var humancount : Integer = LanGetClientsCount;
      [*] = ;         var busycount : Integer;
      [*] = ;         var i : Integer;
      [*] = ;         for i:=0 to gc_MaxPlayerCount-1 do
      [*] = ;         if (gMap.players[i].bclosed) or (gMap.players[i].bai) then
      [*] = ;         busycount := busycount+1;
      [*] = ;         if (gInternetShell.bautosearch) then
      [*] = ;         begin
      [*] = ;            if humancount>gint_quickplay_countofplayers then
      [*] = ;            begin
      [*] = ;               Log('LanKillClient AUTOSEARCH');
      [*] = ;               LanKillClient(tag);
      [*] = ;            end;
      [*] = ;         end
      [*] = ;         else
      [*] = ;         if ((busycount+humancount)>=gc_MaxPlayerCount) then
      [*] = ;         begin
      [*] = ;            log('9th player not supported. lan kill client = '+IntToStr(tag));
      [*] = ;            LanKillClient(tag);
      [*] = ;         end;
      [*] = ;      end
      [*] = ;      else
      [*] = ;      begin
      [*] = ;         gInternetShell.currentsessionid := idTo;
      [*] = ;         Log('OnConnect : gInternetShell.currentsessionid = '+IntToStr(gInternetShell.currentsessionid));
      [*] = ;      end;
      [*] = ;      if (not gInternetShell.bautosearch) then
      [*] = ;      begin
      [*] = ;         gbool_gui_updatecurrentsessionname := True;
      [*] = ;         gbool_gui_refreshcurrentsession := True;
      [*] = ;         gbool_gui_senddatasyncparser := True;
      [*] = ;      end;
      [*] = ;      if (gInternetShell.bshowroom) then
      [*] = ;      begin
      [*] = ;         if (gInternetShell.bhistoricalbattle) then
      [*] = ;         gbool_gui_showhistoricalbattle := True
      [*] = ;         else
      [*] = ;         gbool_gui_showcustomgame := True;
      [*] = ;      end;
      [*] = ;   end;
      [*] = ;end;
      [*] = ;
      [*] = ;procedure DoStartGame;
      [*] = ;begin
      [*] = ;   if (_net_IsOnline) and (gMap.brating) and (LanGetClientsCount>1) and (not StrExists(LanPublicServerProfCountry, '|f=')) then
      [*] = ;   begin
      [*] = ;      LanSetMyCountry(LanPublicServerProfCountry+'|f='+IntToStr(GetLanMode));
      [*] = ;      LanPublicServerRegister;
      [*] = ;   end;
      [*] = ;
      [*] = ;   ExecuteState('DoNewGame');
      [*] = ;end;
      [*] = ;
      [*] = ;procedure ParserReceived;
      [*] = ;begin
      [*] = ;   if (GetLanMode<>0) then
      [*] = ;   begin
      [*] = ;      if (cAllowDebug) then
      [*] = ;      Log('ParserReceived : GetLanMode = '+IntToStr(GetLanMode)+' LanGetParserID = '+IntToStr(LanGetParserID));
      [*] = ;      var idFrom : Integer = LanPublicServerGetRegIDFrom;
      [*] = ;      var indFrom : Integer = _misc_GetMapPlayerIndexByLanID(idFrom);
      [*] = ;      var pLan : Integer = LanSelectParser;
      [*] = ;      if (GetLanMode>=gc_lanmode_server) then // server
      [*] = ;      begin
      [*] = ;         case (LanGetParserID) of
      [*] = ;            gc_LAN_ROOM_READY : begin
      [*] = ;               if (indFrom>=0) then
      [*] = ;               gMap.players[indFrom].bready := True;
      [*] = ;               gbool_gui_updatecurrentsessionname := True;
      [*] = ;               if (gInternetShell.bshowroom) then
      [*] = ;               begin
      [*] = ;                  if (gInternetShell.bhistoricalbattle) then
      [*] = ;                  gbool_gui_showhistoricalbattle := True
      [*] = ;                  else
      [*] = ;                  gbool_gui_showcustomgame := True;
      [*] = ;               end;
      [*] = ;               gbool_gui_senddatasyncparser := True;
      [*] = ;            end;
      [*] = ;            else
      [*] = ;            ErrorLog('leParser unknown ID = '+IntToStr(LanGetParserID));
      [*] = ;         end;
      [*] = ;      end
      [*] = ;      else
      [*] = ;      if (GetLanMode=gc_lanmode_client) then
      [*] = ;      begin
      [*] = ;         case (LanGetParserID) of
      [*] = ;            gc_LAN_GENERATE : begin
      [*] = ;               Log('gc_LAN_GENERATE : should be done bofore DoStartGame on leGenerate');
      [*] = ;               StateMachineGlobalVariablesLoadFromParser(pLan, 'gMap', False, False);
      [*] = ;               gbool_gui_hidenicks := gMap.brating;
      [*] = ;               LanDoStart();
      [*] = ;            end;
      [*] = ;         end;
      [*] = ;      end;
      [*] = ;   end;
      [*] = ;end;
      [*] = ;
      [*] = ;procedure ErrorOccur;
      [*] = ;begin
      [*] = ;   ErrorLog('ErrorOccur : OnLanEvent');
      [*] = ;   OnTerminateGame;
      [*] = ;   gInternetShell.Clear(False);
      [*] = ;   LanShutdown;
      [*] = ;end;
      [*] = ;
      [*] = ;procedure CoreVersionFailed;
      [*] = ;begin
      [*] = ;   ErrorLog('CoreVersionFailed');
      [*] = ;   _gui_ShowConnectStateMessage(gc_ConnectState_CoreVersionFailed);
      [*] = ;end;
      [*] = ;
      [*] = ;procedure DataVersionFailed;
      [*] = ;begin
      [*] = ;   ErrorLog('DataVersionFailed');
      [*] = ;   _gui_ShowConnectStateMessage(gc_ConnectState_DataVersionFailed);
      [*] = ;end;
      [*] = ;
      [*] = ;gfloat_gui_lanlasteventreceived := _misc_GetRealTime;
      [*] = ;
      [*] = ;if (IsLanPublicServerMode) then
      [*] = ;begin
      [*] = ;   //------------------------------------------------------------------------------
      [*] = ;   if (gLanEvent<>leShellMessage) and (cAllowDebug) and ((gLanEvent<>leShellMessage) or (LanPublicServerGetRegIDFrom<>LanPublicServerGetRegIDTo)) then
      [*] = ;   Log('gLanEvent='+IntToStr(gLanEvent)+' RegIDFrom = '+IntToStr(LanPublicServerGetRegIDFrom)+' RegIDTo = '+ IntToStr(LanPublicServerGetRegIDTo)+' tag='+IntToStr(GetIntValueByName('Tag'))+' index='+IntToStr(LanGetClientIndexByID(GetIntValueByName('Tag'))));
      [*] = ;   //------------------------------------------------------------------------------
      [*] = ;   case gLanEvent of
      [*] = ;      leTerminated : OnTerminateGame;
      [*] = ;      leError : begin
      [*] = ;         _misc_LanCustErrCodeHandler();
      [*] = ;         ErrorOccur;
      [*] = ;      end;
      [*] = ;      leShellCoreVersionFailed : CoreVersionFailed;
      [*] = ;      leShellDataVersionFailed : DataVersionFailed;
      [*] = ;      leShellGetAuth : begin
      [*] = ;         LogEvent('leShellGetAuth');
      [*] = ;         if (gReconnectManager.prevstate=1) and (gReconnectManager.bsessionstarted) and (not gReconnectManager.bimpossibletoreconnect) then
      [*] = ;         begin
      [*] = ;            gReconnectManager.prevstate := 2;
      [*] = ;            Log('gReconnectManager.prevstate=1 : LanPublicServerLogin : set to 2');
      [*] = ;            LanPublicServerLogin;
      [*] = ;         end
      [*] = ;         else
      [*] = ;         begin
      [*] = ;            gInternetShell.prevstate := 2;
      [*] = ;            if (gint_gui_connectserverstate=2) then
      [*] = ;            begin
      [*] = ;               gint_gui_connectserverstate := 3;
      [*] = ;               LanPublicServerLogin;
      [*] = ;            end
      [*] = ;            else
      [*] = ;            begin
      [*] = ;               if (False) and (gProfile.netemail<>'') then
      [*] = ;               begin
      [*] = ;                  LanSetMyEmail(gProfile.netemail);
      [*] = ;                  LanPublicServerUserExist(gProfile.netemail);
      [*] = ;               end
      [*] = ;               else
      [*] = ;               begin
      [*] = ;                  gInternetShell.currentsessionid := 0;
      [*] = ;                  gInternetShell.selsessionid := 0;
      [*] = ;                  gInternetShell.roomdata := '';
      [*] = ;                  _gui_ShowConnectStateMessage(gc_ConnectState_Hide);
      [*] = ;                  gConnectLoginState := gc_ConnectLoginState_YourEmail;
      [*] = ;                  ExecuteState('ShowMultiplayerLogin');
      [*] = ;               end;
      [*] = ;            end;
      [*] = ;         end;
      [*] = ;      end;
      [*] = ;      leShellValidEmail : begin
      [*] = ;         LogEvent('leShellValidEmail');
      [*] = ;         gInternetShell.prevstate := 3;
      [*] = ;         _gui_ShowConnectStateMessage(gc_ConnectState_Hide);
      [*] = ;         gConnectLoginState := gc_ConnectLoginState_ValidEmail;
      [*] = ;         ExecuteState('ShowMultiplayerLogin');
      [*] = ;      end;
      [*] = ;      leShellInvalidEmail : begin
      [*] = ;         LogEvent('leShellInvalidEmail');
      [*] = ;         _gui_ShowConnectStateMessage(gc_ConnectState_Hide);
      [*] = ;         gConnectLoginState := gc_ConnectLoginState_InvalidEmail;
      [*] = ;         ExecuteState('ShowMultiplayerLogin');
      [*] = ;      end;
      [*] = ;      leShellLogged : begin
      [*] = ;         gInternetShell.prevstate := 4;
      [*] = ;         gLanMyID := LanMyInfoID;
      [*] = ;         LogEvent('leShellLogged');
      [*] = ;         _gui_ShowConnectStateMessage(gc_ConnectState_Connecting);
      [*] = ;         gInternetShell.bauth := True;
      [*] = ;         gInternetShell.qprankedgame := True;
      [*] = ;         gInternetShell.autosearchantispamlasttime := 0;
      [*] = ;         if (gReconnectManager.prevstate=2) and (gReconnectManager.bsessionstarted) and (not gReconnectManager.bimpossibletoreconnect) then
      [*] = ;         begin
      [*] = ;            gReconnectManager.prevstate := 4;
      [*] = ;            Log('gReconnectManager.prevstate=2 : bsuccessreconnectserver := True : set to 4 : ');
      [*] = ;            gReconnectManager.bsuccessreconnectserver := True;
      [*] = ;            gReconnectManager.bconnectedserver := True;
      [*] = ;         end
      [*] = ;         else
      [*] = ;         begin
      [*] = ;            var country : String = LanPublicServerProfCountry;
      [*] = ;            if (StrExists(country, '|f=')) then
      [*] = ;            begin
      [*] = ;               LanPublicServerWrongCloseSession;
      [*] = ;               var pos : Integer = StrPos('|f=', country);
      [*] = ;               var lm : String = SubStr(country, pos+3, 1);
      [*] = ;               country := StrReplace(country, '|f='+lm, '');
      [*] = ;               LanSetMyCountry(country);
      [*] = ;               LanPublicServerRegister;
      [*] = ;            end;
      [*] = ;         end;
      [*] = ;      end;
      [*] = ;      //
      [*] = ;      leShellAuthClientFailed : _gui_ShowConnectStateMessage(gc_ConnectState_InvalidPass);
      [*] = ;      leShellAuthBannedFailed : _gui_ShowConnectStateMessage(gc_ConnectState_AccountBanned);
      [*] = ;      leShellAuthCDKeyFailed : _gui_ShowConnectStateMessage(gc_ConnectState_InvalidKey);
      [*] = ;      //
      [*] = ;      leShellRegClientFailed : _gui_ShowConnectStateMessage(gc_ConnectState_RegClientFailed);
      [*] = ;      leShellRegCDKeyFailed : _gui_ShowConnectStateMessage(gc_ConnectState_RegCDKeyFailed);
      [*] = ;      leShellRegDataFailed : _gui_ShowConnectStateMessage(gc_ConnectState_RegDataFailed);
      [*] = ;      //
      [*] = ;      leShellMessage, leShellSessionMessage : begin
      [*] = ;         var idFrom : Integer = LanPublicServerGetRegIDFrom;
      [*] = ;         var idTo : Integer = LanPublicServerGetRegIDTo;
      [*] = ;         var msg : String = LanPublicServerGetRegMessage;
      [*] = ;         if (msg<>'') then
      [*] = ;         begin
      [*] = ;            case msg of
      [*] = ;               '/clear', '/c' : begin
      [*] = ;                  if (idFrom=LanMyInfoID) then // check if i need this
      [*] = ;                  begin
      [*] = ;                     gInternetShell.ClearChat((gLanEvent=leShellMessage), (gLanEvent=leShellSessionMessage));
      [*] = ;                     _misc_FillChatList(False);
      [*] = ;                  end;
      [*] = ;               end;
      [*] = ;               else
      [*] = ;               if (SubStr(msg, 0, 1)=#9) then
      [*] = ;               begin
      [*] = ;                  if (gInternetShell.bautosearch) and (idTo=LanMyInfoID) then
      [*] = ;                  gInternetShell.autosearchdocreate := msg;
      [*] = ;               end
      [*] = ;               else
      [*] = ;               begin
      [*] = ;                  const cPurgeSize = 16;
      [*] = ;                  var nickFrom, nickTo : String;
      [*] = ;                  var pclient : Pointer = gInternetShell.clients.GetByLanID(idFrom);
      [*] = ;                  if (pclient<>nil) then
      [*] = ;                  nickFrom := TInternetShellClient(pclient).nick;
      [*] = ;                  pclient := gInternetShell.clients.GetByLanID(idTo);
      [*] = ;                  if (pclient<>nil) then
      [*] = ;                  nickTo := TInternetShellClient(pclient).nick;
      [*] = ;                  var lang : String;
      [*] = ;                  _profile_ConvertConfigValueToLocale(gProfile.lang, lang);
      [*] = ;                  if (gLanEvent=leShellSessionMessage) or ((idTo<>0) and (idFrom<>idTo)) then
      [*] = ;                  begin
      [*] = ;                     if (gInternetShell.roomchatind>gc_gui_maxinternetchatlog-1) then
      [*] = ;                     begin
      [*] = ;                        var i : Integer;
      [*] = ;                        for i:=0 to gc_gui_maxinternetchatlog-cPurgeSize-1 do
      [*] = ;                        gInternetShell.roomchat[i] := gInternetShell.roomchat[i+cPurgeSize];
      [*] = ;                        for i:=gc_gui_maxinternetchatlog-cPurgeSize to gc_gui_maxinternetchatlog-1 do
      [*] = ;                        gInternetShell.roomchat[i] := '';
      [*] = ;                        gInternetShell.roomchatind := gc_gui_maxinternetchatlog-cPurgeSize;
      [*] = ;                     end;
      [*] = ;                     var spacepos : Integer = StrPos(' ', msg);
      [*] = ;                     var firstword : String = SubStr(msg, 1, spacepos);
      [*] = ;                     case firstword of
      [*] = ;                        '/help', '/h' : begin
      [*] = ;                           msg := msg+'/help, /h - to see list of commands'+gc_gui_breakline;
      [*] = ;                        msg := msg+'/w nick - send private message to nick'+gc_gui_breakline;
      [*] = ;                           msg := msg+'/clear, /c - clear chat history'+gc_gui_breakline;
      [*] = ;                        end;
      [*] = ;                     end;
      [*] = ;                     var newmsg : String = IntToStr(idFrom)+'|'+IntToStr(idTo)+'|'+nickFrom+'|'+nickTo+'|'+lang+'|"'+msg+'"';
      [*] = ;                     gInternetShell.roomchat[gInternetShell.roomchatind] := newmsg;
      [*] = ;                     gInternetShell.roomchatind := gInternetShell.roomchatind+1;
      [*] = ;                  end;
      [*] = ;                  if (gLanEvent=leShellMessage) or ((idTo<>0) and (idFrom<>idTo)) then
      [*] = ;                  begin
      [*] = ;                     if (gInternetShell.chatind>gc_gui_maxinternetchatlog-1) then
      [*] = ;                     begin
      [*] = ;                        var i : Integer;
      [*] = ;                        for i:=0 to gc_gui_maxinternetchatlog-cPurgeSize-1 do
      [*] = ;                        gInternetShell.chat[i] := gInternetShell.chat[i+cPurgeSize];
      [*] = ;                        for i:=gc_gui_maxinternetchatlog-cPurgeSize to gc_gui_maxinternetchatlog-1 do
      [*] = ;                        gInternetShell.chat[i] := '';
      [*] = ;                        gInternetShell.chatind := gc_gui_maxinternetchatlog-cPurgeSize;
      [*] = ;                     end;
      [*] = ;                     var spacepos : Integer = StrPos(' ', msg);
      [*] = ;                     var firstword : String = SubStr(msg, 1, spacepos);
      [*] = ;                     case firstword of
      [*] = ;                        '/help', '/h' : begin
      [*] = ;                           msg := msg+'/help, /h - to see list of commands'+gc_gui_breakline;
      [*] = ;                        msg := msg+'/w nick - send private message to nick'+gc_gui_breakline;
      [*] = ;                           msg := msg+'/clear, /c - clear chat history'+gc_gui_breakline;
      [*] = ;                        end;
      [*] = ;                     end;
      [*] = ;                     var newmsg : String = IntToStr(idFrom)+'|'+IntToStr(idTo)+'|'+nickFrom+'|'+nickTo+'|'+lang+'|"'+msg+'"';
      [*] = ;                     gInternetShell.chat[gInternetShell.chatind] := newmsg;
      [*] = ;                     gInternetShell.chatind := gInternetShell.chatind+1;
      [*] = ;                  end;
      [*] = ;                  //gInternetShell.chatkeyscrollind := gInternetShell.chatind;
      [*] = ;                  if (idTo<>0)
      [*] = ;                  or ((gInternetShell.bshowroom) and (gLanEvent=leShellSessionMessage))
      [*] = ;                  or ((not gInternetShell.bshowroom) and (gLanEvent=leShellMessage)) then
      [*] = ;                  _misc_FillChatList(True);
      [*] = ;               end;
      [*] = ;            end;
      [*] = ;         end;
      [*] = ;      end;
      [*] = ;      leShellSessionCreate : begin
      [*] = ;         LogEvent('leShellSessionCreate');
      [*] = ;         var idFrom : Integer = LanPublicServerGetRegIDFrom;
      [*] = ;         if (idFrom=LanMyInfoID) then
      [*] = ;         begin
      [*] = ;            if (not gInternetShell.bautosearch) then
      [*] = ;            begin
      [*] = ;               gbool_gui_updatecurrentsessionname := True;
      [*] = ;               gbool_gui_refreshcurrentsession := True;
      [*] = ;               gint_gui_updatesessionlist := (1 shl 0);
      [*] = ;               _gui_SendTagToState('EventInternetShell', gc_gui_event_tagHide);
      [*] = ;               gInternetShell.bshowroom := True;
      [*] = ;               gInternetShell.bshowranking := False;
      [*] = ;               if (gInternetShell.bhistoricalbattle) then
      [*] = ;               gbool_gui_showhistoricalbattle := True
      [*] = ;               else
      [*] = ;               gbool_gui_showcustomgame := True;
      [*] = ;               gbool_gui_setshellchatinputfocused := True;
      [*] = ;            end
      [*] = ;            else
      [*] = ;            gint_gui_updatesessionlist := (1 shl 0) or (1 shl 1) or (1 shl 3);
      [*] = ;         end
      [*] = ;         else
      [*] = ;         begin
      [*] = ;            gint_gui_updatesessionlist := (1 shl 0) or (1 shl 1) or (1 shl 3);
      [*] = ;            LanPublicServerUpdateClientInfo(idFrom);
      [*] = ;         end;
      [*] = ;
      [*] = ;         var pClient : Integer = _parser_ParserTemporary(True);
      [*] = ;         if (LanPublicServerGetClientInfoToParserByClientID(idFrom, pClient)) then
      [*] = ;         begin
      [*] = ;            gInternetShell.clients.AddOrUpdateFromParser(pClient);
      [*] = ;            if (not gInternetShell.bshowroom) then
      [*] = ;            gbool_gui_showinternetshell := True;
      [*] = ;         end;
      [*] = ;      end;
      [*] = ;      leShellSessionJoin : begin
      [*] = ;         LogEvent('leShellSessionJoin');
      [*] = ;         var idTo : Integer = LanPublicServerGetRegIDTo;
      [*] = ;         var idFrom : Integer = LanPublicServerGetRegIDFrom;
      [*] = ;         if (idTo=LanMyInfoID) then
      [*] = ;         begin
      [*] = ;            {// I am server and someone joined my room.
      [*] = ;            var pLan : Integer = _parser_ParserTemporary(True);
      [*] = ;            ParserSetValueByKeyByHandle(pLan, 's', gInternetShell.roomdata);
      [*] = ;            LanPublicServerSendSessionParser(idFrom, gc_LAN_ROOM_SERVER_DATASYNC, pLan);}
      [*] = ;         end
      [*] = ;         else
      [*] = ;         if (idFrom=LanMyInfoID) then
      [*] = ;         begin
      [*] = ;            if (not gInternetShell.bautosearch) then
      [*] = ;            begin
      [*] = ;               gbool_gui_refreshcurrentsession := True;
      [*] = ;               _misc_UpdateSessionList(True, False, False, False);
      [*] = ;               _gui_SendTagToState('EventInternetShell', gc_gui_event_tagHide);
      [*] = ;               gInternetShell.bshowroom := True;
      [*] = ;               gInternetShell.bshowranking := False;
      [*] = ;               if (gInternetShell.bhistoricalbattle) then
      [*] = ;               gbool_gui_showhistoricalbattle := True
      [*] = ;               else
      [*] = ;               gbool_gui_showcustomgame := True;
      [*] = ;            end
      [*] = ;            else
      [*] = ;            gint_gui_updatesessionlist := (1 shl 0) or (1 shl 1) or (1 shl 3);
      [*] = ;         end
      [*] = ;         else
      [*] = ;         gint_gui_updatesessionlist := (1 shl 0) or (1 shl 1) or (1 shl 3);
      [*] = ;
      [*] = ;         var pClient : Integer = _parser_ParserTemporary(True);
      [*] = ;         if (LanPublicServerGetClientInfoToParserByClientID(idFrom, pClient)) then
      [*] = ;         begin
      [*] = ;            gInternetShell.clients.AddOrUpdateFromParser(pClient);
      [*] = ;            if (not gInternetShell.bshowroom) then
      [*] = ;            gint_gui_updateclientlist := (1 shl 0) or (1 shl 1) or (1 shl 3);
      [*] = ;         end;
      [*] = ;      end;
      [*] = ;      leShellSessionLeave : begin
      [*] = ;         LogEvent('leShellSessionLeave');
      [*] = ;         var idFrom : Integer = LanPublicServerGetRegIDFrom;
      [*] = ;         var idTo : Integer = LanPublicServerGetRegIDTo;
      [*] = ;         if (idTo=LanMyInfoID) and (_net_IsOnline) then
      [*] = ;         begin
      [*] = ;            // i am server and client decided to leave room
      [*] = ;            if (not gInternetShell.bautosearch) or (gInternetShell.bratingroom) then
      [*] = ;            begin
      [*] = ;               if (gMap.bbattle) and (gMap.battlestage=1) then
      [*] = ;               begin
      [*] = ;                  gMap.battlestage := 0;
      [*] = ;                  var i : Integer;
      [*] = ;                  for i:=0 to gc_MaxPlayerCount-1 do
      [*] = ;                  begin
      [*] = ;                     gMap.players[i].cid := gc_MaxCountryCount;
      [*] = ;                     if (i>0) then
      [*] = ;                     gMap.players[i].bready := False;
      [*] = ;                     gMap.players[i].bclosed := False;
      [*] = ;                  end;
      [*] = ;               end;
      [*] = ;               gbool_gui_updatecurrentsessionname := True;
      [*] = ;               gbool_gui_refreshcurrentsession := True;
      [*] = ;               gbool_gui_senddatasyncparser := True;
      [*] = ;            end;
      [*] = ;            if (gInternetShell.bshowroom) then
      [*] = ;            begin
      [*] = ;               if(gInternetShell.bhistoricalbattle) then
      [*] = ;               gbool_gui_showhistoricalbattle := True
      [*] = ;               else
      [*] = ;               gbool_gui_showcustomgame := True;
      [*] = ;            end;
      [*] = ;         end
      [*] = ;         else
      [*] = ;         if (idFrom=LanMyInfoID) and (_net_IsOnline) then
      [*] = ;         begin
      [*] = ;            if (not gInternetShell.bautosearch) then
      [*] = ;            begin
      [*] = ;               gInternetShell.bshowroom := False;
      [*] = ;               gInternetShell.bshowranking := False;
      [*] = ;               gInternetShell.roomdata := '';
      [*] = ;               gint_gui_updatesessionlist := (1 shl 0) or (1 shl 1) or (1 shl 3);
      [*] = ;               LanTerminateGame;
      [*] = ;               _gui_ShowConnectStateMessage(gc_ConnectState_SessionKick);
      [*] = ;            end;
      [*] = ;         end
      [*] = ;         else
      [*] = ;         if (idFrom=LanMyInfoID) then
      [*] = ;         begin
      [*] = ;            if gInternetShell.bshowroom then
      [*] = ;            begin
      [*] = ;               gbool_gui_setshellchatinputfocused := True;
      [*] = ;               gInternetShell.bshowroom := False;
      [*] = ;            end;
      [*] = ;            //gInternetShell.bshowranking := False;
      [*] = ;            gInternetShell.roomdata := '';
      [*] = ;            gint_gui_updateclientlist := (1 shl 0);
      [*] = ;            gint_gui_updatesessionlist := (1 shl 0);
      [*] = ;            _gui_SendTagToState('EventCustomGame', gc_gui_event_tagHide);
      [*] = ;            _gui_SendTagToState('EventHistoricalBattle', gc_gui_event_tagHide);
      [*] = ;            gbool_gui_showinternetshell := True;
      [*] = ;         end;
      [*] = ;
      [*] = ;         var pClient : Integer = _parser_ParserTemporary(True);
      [*] = ;         if (LanPublicServerGetClientInfoToParserByClientID(idFrom, pClient)) then
      [*] = ;         begin
      [*] = ;            gInternetShell.clients.AddOrUpdateFromParser(pClient);
      [*] = ;            gInternetShell.sessions.DeleteByMasterID(idFrom);
      [*] = ;            if (not gInternetShell.bshowroom) then
      [*] = ;            begin
      [*] = ;               gint_gui_updateclientlist := (1 shl 0);
      [*] = ;               gint_gui_updatesessionlist := (1 shl 0);
      [*] = ;               if gQuickPlay.IndexOf(idFrom)=-1 then // remove blinking on quickplay recreate room
      [*] = ;               gbool_gui_showinternetshell := True;
      [*] = ;            end;
      [*] = ;         end;
      [*] = ;      end;
      [*] = ;      leShellSessionInfo : begin
      [*] = ;         LogEvent('leShellSessionInfo');
      [*] = ;         var idFrom : Integer = LanPublicServerGetRegIDFrom;
      [*] = ;         if (idFrom=LanMyInfoID) then
      [*] = ;         gbool_gui_refreshcurrentsession := True;
      [*] = ;         gint_gui_updatesessionlist := (1 shl 0);
      [*] = ;         if (not gInternetShell.bshowroom) then
      [*] = ;         gbool_gui_showinternetshell := true;
      [*] = ;      end;
      [*] = ;      leShellSessionLock : begin
      [*] = ;         LogEvent('leShellSessionLock');
      [*] = ;         var idFrom : Integer = LanPublicServerGetRegIDFrom;
      [*] = ;         var pClient : Integer = _parser_ParserTemporary(True);
      [*] = ;         if (LanPublicServerGetClientInfoToParserByClientID(idFrom, pClient)) then
      [*] = ;         begin
      [*] = ;            var visiblename, pass, roomchecksum : String;
      [*] = ;            var psession : Pointer = gInternetShell.sessions.GetByMasterID(idFrom);
      [*] = ;            _misc_GetGameNameAndPasswordBySession(psession, visiblename, pass, roomchecksum);
      [*] = ;            if (gbool_lan_debug) then
      [*] = ;            begin
      [*] = ;               if pass=gc_quickplay_roompass then
      [*] = ;               Log('locked [RATE] : '+visiblename)
      [*] = ;               else
      [*] = ;               Log('locked : '+visiblename);
      [*] = ;            end;
      [*] = ;
      [*] = ;            gInternetShell.clients.AddOrUpdateFromParser(pClient);
      [*] = ;            if (psession<>nil) then
      [*] = ;            TInternetShellSession(psession).blocked := True;
      [*] = ;            if (not gbool_lan_debug) then
      [*] = ;            gInternetShell.sessions.DeleteByMasterID(idFrom);
      [*] = ;            if (not gInternetShell.bshowroom) then
      [*] = ;            gbool_gui_showinternetshell := True;
      [*] = ;         end;
      [*] = ;      end;
      [*] = ;      leShellSessionClose : begin
      [*] = ;      end;
      [*] = ;      leShellClientConnected : begin
      [*] = ;         LogEvent('leShellClientConnected');
      [*] = ;         var idFrom : Integer = LanPublicServerGetRegIDFrom;
      [*] = ;         if (idFrom=LanMyInfoID) then
      [*] = ;         begin
      [*] = ;            LanPublicServerUpdateClientInfo(idFrom);
      [*] = ;
      [*] = ;            _gui_SendTagToState('EventMultiplayerLogin', gc_gui_event_tagHide);
      [*] = ;            _gui_ShowConnectStateMessage(gc_ConnectState_Hide);
      [*] = ;
      [*] = ;            gInternetShell.Clear(False);
      [*] = ;            gInternetShell.lanid := LanMyInfoID;
      [*] = ;
      [*] = ;            //gInternetShell.clients.Clear;
      [*] = ;            var pClients : Integer = _parser_ParserTemporary(True);
      [*] = ;            LanPublicServerClientsToParser(pClients);
      [*] = ;            var i : Integer;
      [*] = ;            for i:=0 to ParserGetCountByHandle(pClients)-1 do
      [*] = ;            begin
      [*] = ;               var pClient : Integer = ParserSelectByHandleByIndex(pClients, i);
      [*] = ;               if pClient<>0 then
      [*] = ;               gInternetShell.clients.AddOrUpdateFromParser(pClient);
      [*] = ;            end;
      [*] = ;
      [*] = ;            //gInternetShell.sessions.Clear;
      [*] = ;            var pSessions : Integer = _parser_ParserTemporary(True);
      [*] = ;            LanPublicServerSessionsToParser(pSessions);
      [*] = ;            gInternetShell.sessions.Clear;
      [*] = ;            for i:=0 to ParserGetCountByHandle(pSessions)-1 do
      [*] = ;            begin
      [*] = ;               var pSession : Integer = ParserSelectByHandleByIndex(pSessions, i);
      [*] = ;               if pSession<>0 then
      [*] = ;               gInternetShell.sessions.AddFromParser(pSession);
      [*] = ;            end;
      [*] = ;
      [*] = ;            gInternetShell.bshowroom := False;
      [*] = ;            gInternetShell.bshowranking := False;
      [*] = ;            gInternetShell.currentpage := gc_internetshell_currentpage_sessions;
      [*] = ;            ExecuteState('ShowInternetShell');
      [*] = ;            _gui_SetShellChatInputBoxFocused;
      [*] = ;            if (gProfileTmp.netemail<>gProfile.netemail) or (gProfile.netpass<>gProfileTmp.netpass) or (gProfile.netcdkey<>gProfileTmp.netcdkey) then
      [*] = ;            begin
      [*] = ;               gProfile.netemail := gProfileTmp.netemail;
      [*] = ;               gProfile.netpass := gProfileTmp.netpass;
      [*] = ;               gProfile.netcdkey := gProfileTmp.netcdkey;
      [*] = ;               _profile_SaveUserProfile;
      [*] = ;            end;
      [*] = ;
      [*] = ;            // combine info
      [*] = ;            var previnfo : String = LanPublicServerProfInfo;
      [*] = ;            var newinfo : String;
      [*] = ;            _misc_LanCombinePlayerInfo(previnfo, newinfo);
      [*] = ;            if (previnfo<>newinfo) then
      [*] = ;            begin
      [*] = ;               LanSetMyProfInfo(newinfo);
      [*] = ;               LanPublicServerRegister;
      [*] = ;            end;
      [*] = ;
      [*] = ;            if (not gbool_internetshell_firstappearance) then
      [*] = ;            begin
      [*] = ;               var txtwelcome, txt : String;
      [*] = ;               _misc_GetNewTextLocale('internetshell.welcome.new', txtwelcome);
      [*] = ;               txtwelcome := gc_font_color_white+txtwelcome+gc_font_color_default;
      [*] = ;               //_misc_GetNewTextLocale('internetshell.welcome.newsexists', txt);
      [*] = ;               txtwelcome := txtwelcome+gc_gui_breakline;
      [*] = ;               _misc_GetNewTextLocale('internetshell.season5.start', txt);
      [*] = ;               txtwelcome := txtwelcome+gc_gui_breakline+txt;
      [*] = ;               LanPublicServerSendMessage(idFrom, txtwelcome);
      [*] = ;               gbool_internetshell_firstappearance := True;
      [*] = ;            end;
      [*] = ;         end
      [*] = ;         else
      [*] = ;         begin
      [*] = ;            var pClient : Integer = _parser_ParserTemporary(True);
      [*] = ;            if (LanPublicServerGetClientInfoToParserByClientID(idFrom, pClient)) then
      [*] = ;            begin
      [*] = ;               gInternetShell.clients.AddOrUpdateFromParser(pClient);
      [*] = ;               if (not gInternetShell.bshowroom) then
      [*] = ;               gbool_gui_showinternetshell := True;
      [*] = ;            end;
      [*] = ;         end;
      [*] = ;      end;
      [*] = ;      leShellClientDisconnected : begin
      [*] = ;         LogEvent('DisconnectClient');
      [*] = ;         var idFrom : Integer = LanPublicServerGetRegIDFrom;
      [*] = ;         if (idFrom<>LanMyInfoID) then
      [*] = ;         begin
      [*] = ;            gInternetShell.clients.RemoveByLanID(idFrom);
      [*] = ;            if (not gInternetShell.bshowroom) then
      [*] = ;            begin
      [*] = ;               gint_gui_updateclientlist := (1 shl 0);
      [*] = ;               gint_gui_updatesessionlist := (1 shl 0);
      [*] = ;               gbool_gui_showinternetshell := True;
      [*] = ;            end;
      [*] = ;         end;
      [*] = ;      end;
      [*] = ;      leShellClientInfo : begin
      [*] = ;         var idFrom : Integer = LanPublicServerGetRegIDFrom;
      [*] = ;         LogEvent('leShellClientInfo : '+IntToStr(idFrom));
      [*] = ;         if (idFrom=LanMyInfoID) then
      [*] = ;         begin
      [*] = ;            var parser : Integer = _parser_ParserTemporary(True);
      [*] = ;            if (LanPublicServerGetClientInfoToParserByClientID(idFrom, parser)) then
      [*] = ;            begin
      [*] = ;               var pclient : Pointer = gInternetShell.clients.GetByLanID(idFrom);
      [*] = ;               if pclient<>nil then
      [*] = ;               begin
      [*] = ;                  gInternetShell.clients.AddOrUpdateFromParser(parser);
      [*] = ;                  //TInternetShellClient(pclient).score := ParserGetIntValueByKeyByHandle(parser, 'Score');
      [*] = ;                  // combine info
      [*] = ;                  {var profinfo : String = LanPublicServerProfInfo;
      [*] = ;                  if profinfo='' then
      [*] = ;                  exit;
      [*] = ;                  log('LanPublicServerProfInfo='+LanPublicServerProfInfo);
      [*] = ;                  var pos : Integer = StrPos('sco|', profinfo);
      [*] = ;                  var curinfo, scoinfo, newinfo : String;
      [*] = ;                  if (pos>0) then
      [*] = ;                  begin
      [*] = ;                     curinfo := SubStr(profinfo, 1, pos-2);
      [*] = ;                     scoinfo := SubStr(profinfo, pos, StrLength(profinfo)-pos+1);
      [*] = ;                  end;
      [*] = ;                  //var newscoinfo : String = 'sco|'+IntToStr(TInternetShellClient(pclient).score);
      [*] = ;                  var newscoinfo : String = 'sco|'+IntToStr(LanPublicServerProfScore);
      [*] = ;                  if (scoinfo<>newscoinfo) then
      [*] = ;                  begin
      [*] = ;                     if curinfo<>'' then
      [*] = ;                     newinfo := curinfo+'|';
      [*] = ;                     newinfo := newinfo+newscoinfo;
      [*] = ;                     log('new info = '+newinfo);
      [*] = ;                     LanSetMyProfInfo(newinfo);
      [*] = ;                     LanPublicServerRegister;
      [*] = ;                  end;}
      [*] = ;               end;
      [*] = ;            end;
      [*] = ;         end;
      [*] = ;
      [*] = ;         LogEvent('leShellClientInfo');
      [*] = ;      end;
      [*] = ;      leSessionParser : begin
      [*] = ;         procedure SendRoomDataToClients();
      [*] = ;         begin
      [*] = ;            var humancount : Integer;
      [*] = ;            var i : Integer;
      [*] = ;            for i:=0 to gc_MaxPlayerCount-1 do
      [*] = ;            if (gMap.players[i].bexists) and (gMap.players[i].lanid>0) then
      [*] = ;            humancount := humancount+1;
      [*] = ;            if (LanGetClientsCount>1) then
      [*] = ;            begin
      [*] = ;               var pLan : Integer = _parser_ParserTemporary(True);
      [*] = ;               ParserSetValueByKeyByHandle(pLan, 's', gInternetShell.roomdata);
      [*] = ;               //log('4 : roomdata = '+gInternetShell.roomdata);
      [*] = ;               LanPublicServerSendSessionParser(0, gc_LAN_ROOM_SERVER_DATASYNC, pLan);
      [*] = ;            end;
      [*] = ;         end;
      [*] = ;
      [*] = ;         if (GetLanMode<>0) then
      [*] = ;         begin
      [*] = ;            var idFrom : Integer = LanPublicServerGetRegIDFrom;
      [*] = ;            var idTo : Integer = LanPublicServerGetRegIDTo;
      [*] = ;            if (idFrom<>LanMyInfoID) then
      [*] = ;            begin
      [*] = ;               LogEvent('leSessionParser ID='+IntToStr(LanGetParserID));
      [*] = ;               var pLan : Integer = LanSelectParser;
      [*] = ;               case (LanGetParserID) of
      [*] = ;                  gc_LAN_ROOM_SERVER_DATASYNC : begin
      [*] = ;                     if (_net_IsClient) then
      [*] = ;                     begin
      [*] = ;                        var newroomdata : String = ParserGetValueByKeyByHandle(pLan, 's');
      [*] = ;                        if (gInternetShell.roomdata<>newroomdata) then
      [*] = ;                        begin
      [*] = ;                           gInternetShell.roomdata := newroomdata;
      [*] = ;                           //log('5 : roomdata = '+gInternetShell.roomdata);
      [*] = ;                           _misc_InternetShellRefreshCurrentSession(gInternetShell, True);
      [*] = ;                           var team : Integer = _misc_GetClLanTeamByLanID(LanMyInfoID);
      [*] = ;                           LanClSetMyTeam(team);
      [*] = ;                           Log('Sync LanClSetMyTeam('+IntToStr(team)+')');
      [*] = ;                           if (gInternetShell.bhistoricalbattle) then
      [*] = ;                           gbool_gui_showhistoricalbattle := True
      [*] = ;                           else
      [*] = ;                           gbool_gui_showcustomgame := True;
      [*] = ;                        end;
      [*] = ;                     end;
      [*] = ;                  end;
      [*] = ;                  gc_LAN_ROOM_SERVER_DATACHANGE : ;
      [*] = ;                  gc_LAN_ROOM_CLIENT_DATACHANGE : begin
      [*] = ;                     if (_net_IsServer) then
      [*] = ;                     begin
      [*] = ;                        var indFrom : Integer = _misc_GetMapPlayerIndexByLanID(idFrom);
      [*] = ;                        if (indFrom>=0) then
      [*] = ;                        begin
      [*] = ;                           var s : String = ParserGetValueByKeyByHandle(pLan, 's');
      [*] = ;                           if (IsDelimiterCharExists(s, gc_gui_delimiterchar)) then
      [*] = ;                           begin
      [*] = ;                              var s1, s2, s3, s4 : String;
      [*] = ;                              _misc_GetDelimiterString(s, gc_gui_delimiterchar, s1, s2, s3 ,s4);
      [*] = ;                              gMap.players[indFrom].cid := StrToInt(s1);
      [*] = ;                              gMap.players[indFrom].team := StrToInt(s2);
      [*] = ;                              gMap.players[indFrom].color := StrToInt(s3);
      [*] = ;                              gbool_gui_refreshcurrentsession := True;
      [*] = ;                              gbool_gui_updatecurrentsessionname := True;
      [*] = ;                              if (gInternetShell.bshowroom) then
      [*] = ;                              begin
      [*] = ;                                 if (gInternetShell.bhistoricalbattle) then
      [*] = ;                                 gbool_gui_showhistoricalbattle := True
      [*] = ;                                 else
      [*] = ;                                 gbool_gui_showcustomgame := True;
      [*] = ;                              end;
      [*] = ;                              gbool_gui_senddatasyncparser := True;
      [*] = ;                           end;
      [*] = ;                        end
      [*] = ;                        else
      [*] = ;                        ErrorLog('gc_LAN_ROOM_CLIENT_DATACHANGE : indFrom='+IntToStr(indFrom));
      [*] = ;                     end;
      [*] = ;                  end;
      [*] = ;                  gc_LAN_MODS_MODSYNC_REQUEST : begin
      [*] = ;                     var pSyncMods : Integer = _parser_ParserModsSync(True);
      [*] = ;                     ModLibraryGetParser(pSyncMods, True);
      [*] = ;                     LanPublicServerSendSessionParser(idFrom, gc_LAN_MODS_MODSYNC_PARSER, pSyncMods);
      [*] = ;                  end;
      [*] = ;                  gc_LAN_MODS_MODSYNC_PARSER : begin
      [*] = ;                     if (gbool_modsyncparserwait) then
      [*] = ;                     begin
      [*] = ;                        gbool_modsyncparserwait := False;
      [*] = ;                        LanTerminateGame;
      [*] = ;                        var pSyncMods : Integer = _parser_ParserModsSync(True);
      [*] = ;                        ParserSelectByHandle(pSyncMods);
      [*] = ;                        ParserCopyFromByHandle(pLan);
      [*] = ;                        _gui_ShowConnectStateMessage(gc_ConnectModsState_RoomCheckSumIsDifferent);
      [*] = ;                     end
      [*] = ;                     else
      [*] = ;                     ErrorLog('OnLanEvent : ModSyncParser came after time out');
      [*] = ;                  end;
      [*] = ;                  else
      [*] = ;                  ErrorLog('leParser unknown ID = '+IntToStr(LanGetParserID));
      [*] = ;               end;
      [*] = ;            end;
      [*] = ;         end;
      [*] = ;      end;
      [*] = ;      //
      [*] = ;      // NOTE: recursive in connection cycle : - leShutdown : ExecuteState('SwitchToMenu');
      [*] = ;      //
      [*] = ;      leConnect : OnConnect;
      [*] = ;      leParser : ParserReceived;
      [*] = ;      leServerInfo : begin
      [*] = ;         LogEvent('leServerInfo');
      [*] = ;      end;
      [*] = ;      leShellUpdateTopList : begin
      [*] = ;         Log('leShellUpdateTopList');
      [*] = ;         //LanPublicServerUpdateTopUsers(20);
      [*] = ;         var pLan : Integer = LanSelectParser;
      [*] = ;         //ParserSaveToFileByHandle(pLan, 'top100_season4.cfg');
      [*] = ;         gInternetShell.rankings.Clear;
      [*] = ;         var i : Integer;
      [*] = ;         for i := 0 to ParserGetCountByHandle(pLan)-1 do
      [*] = ;         begin
      [*] = ;            var pItem : Integer = ParserSelectByHandleByIndex(pLan, i);
      [*] = ;            var lanid : Integer = ParserGetIntValueByKeyByHandle(pItem, 'lanid');
      [*] = ;            var nick : String = ParserGetValueByKeyByHandle(pItem, 'nick');
      [*] = ;            var score : Integer = ParserGetIntValueByKeyByHandle(pItem, 'score');
      [*] = ;            var wins : Integer = ParserGetIntValueByKeyByHandle(pItem, 'wins');
      [*] = ;            var games : Integer = ParserGetIntValueByKeyByHandle(pItem, 'games');
      [*] = ;            var bplay, bmaster, bsession, bonline : Boolean;
      [*] = ;            if (i=29) then
      [*] = ;            gInternetShell.mirrormatchscore := score;
      [*] = ;            var pclient : Pointer;
      [*] = ;            if (lanid=0) then
      [*] = ;            pclient := gInternetShell.clients.GetByNick(nick)
      [*] = ;            else
      [*] = ;            pclient := gInternetShell.clients.GetByLanID(lanid);
      [*] = ;            if (pclient<>nil) then
      [*] = ;            begin
      [*] = ;               if (lanid=0) then
      [*] = ;               lanid := TInternetShellClient(pclient).lanid;
      [*] = ;               bplay := TInternetShellClient(pclient).states.bplay;
      [*] = ;               bmaster := TInternetShellClient(pclient).states.bmaster;
      [*] = ;               bsession := TInternetShellClient(pclient).states.bsession;
      [*] = ;               bonline := TInternetShellClient(pclient).states.bonline;
      [*] = ;            end;
      [*] = ;            var rank : Integer = _misc_GetRankByScoreELO(score);
      [*] = ;            gInternetShell.rankings.AddSetup(i, lanid, nick, score, rank, wins, games, bplay, bmaster, bsession, bonline);
      [*] = ;
      [*] = ;            {var sLine : String = IntToStr(i+1)+' '+#9;
      [*] = ;            sLine := sLine + ParserGetValueByKeyByHandle(pItem, 'nick')+' '+#9;
      [*] = ;            //sLine := sLine + ParserGetValueByKeyByHandle(pItem, 'country')+' '+#9;
      [*] = ;            sLine := sLine + GetLocaleTableListItemByID('misc', 'inet.rank.'+IntToStr(_misc_GetRankIndex(ParserGetIntValueByKeyByHandle(pItem, 'score'))))+' '+#9;
      [*] = ;            sLine := sLine + ParserGetValueByKeyByHandle(pItem, 'score')+' '+#9;
      [*] = ;            sLine := sLine + ParserGetValueByKeyByHandle(pItem, 'games')+' '+#9;
      [*] = ;            sLine := sLine + ParserGetValueByKeyByHandle(pItem, 'wins')+' '+#9;
      [*] = ;
      [*] = ;            if ParserGetIntValueByKeyByHandle(pItem, 'games') > 0 then
      [*] = ;            sLine := sLine + IntToStr(Round(100*ParserGetIntValueByKeyByHandle(pItem, 'wins')/ParserGetIntValueByKeyByHandle(pItem, 'games')))+ '%'#9
      [*] = ;            else
      [*] = ;            sLine := sLine + '0%'+ #9;
      [*] = ;
      [*] = ;            Log(sLine);}
      [*] = ;         end;
      [*] = ;         LogEvent('leShellUpdateTopList');
      [*] = ;
      [*] = ;         if (ParserGetCountByHandle(pLan)>30) then
      [*] = ;         begin
      [*] = ;            gInternetShell.bshowranking := True;
      [*] = ;            gbool_gui_showinternetshell := True;
      [*] = ;         end;
      [*] = ;      end;
      [*] = ;      //
      [*] = ;      leShutdown : begin
      [*] = ;         if (gbool_lan_changeprofile) then
      [*] = ;         begin
      [*] = ;            gbool_lan_changeprofile := False;
      [*] = ;            GUIDelayExecuteState('DelayConnectServer', 1);
      [*] = ;            _gui_SendTagToState('EventInternetShell', gc_gui_event_tagHide);
      [*] = ;            _gui_InitShowMainMenu(True);
      [*] = ;         end
      [*] = ;         else
      [*] = ;         begin
      [*] = ;            if (gbool_lan_debug) then
      [*] = ;            TimeLog('leShutdown')
      [*] = ;            else
      [*] = ;            LogEvent('leShutdown');
      [*] = ;
      [*] = ;            if (gReconnectManager.btryreconnect) then
      [*] = ;            begin
      [*] = ;               Log('OnLanEvent.leShutDown : (gReconnectManager.btryreconnect=true) : gReconnectManager.Init(False)');
      [*] = ;               gReconnectManager.Init(False);
      [*] = ;            end;
      [*] = ;
      [*] = ;            if (gstring_gui_connectserver='') then
      [*] = ;            begin
      [*] = ;               if (gInternetShell.prevstate<0) then
      [*] = ;               begin
      [*] = ;                  _gui_SendTagToState('EventInternetShell', gc_gui_event_tagHide);
      [*] = ;                  _gui_InitShowMainMenu(True);
      [*] = ;               end
      [*] = ;               else
      [*] = ;               if (gInternetShell.bauth) then
      [*] = ;               begin
      [*] = ;                  if (gInternetShell.prevstate<5) then
      [*] = ;                  _misc_ConnectIPIndexIncrease;
      [*] = ;                  _gui_ShowConnectStateMessage(gc_ConnectState_Disconnect);
      [*] = ;                  if (gInterface.gamemode=gc_gamemode_mainmenu) then
      [*] = ;                  begin
      [*] = ;                     _gui_InitShowMainMenu(True);
      [*] = ;                     _gui_SetGUIElementVisibleByName('MainMenu.col1', False);
      [*] = ;                  end;
      [*] = ;               end
      [*] = ;               else
      [*] = ;               if (gint_gui_connectserverstate<>1) then
      [*] = ;               begin
      [*] = ;                  _misc_ConnectIPIndexIncrease;
      [*] = ;                  _gui_ShowConnectStateMessage(gc_ConnectState_Disconnect);
      [*] = ;               end;
      [*] = ;               gInternetShell.bauth := False;
      [*] = ;               gInternetShell.prevstate := 1;
      [*] = ;            end;
      [*] = ;         end;
      [*] = ;      end;
      [*] = ;      leClientInfo : LogEvent('leClientInfo');
      [*] = ;      leGenerate : begin
      [*] = ;         Log('leGenerate');
      [*] = ;         gInternetShell.ClearQuickPlay;
      [*] = ;         gInternetShell.rankingslastupdate := 0;
      [*] = ;         DoStartGame;
      [*] = ;      end;
      [*] = ;      leShellClientUpdateInfo : begin
      [*] = ;         LogEvent('leShellClientUpdateInfo');
      [*] = ;      end;
      [*] = ;      leDisconnect : begin
      [*] = ;         LogEvent('leDisconnect');
      [*] = ;         //var idFrom : Integer = LanPublicServerGetRegIDFrom;
      [*] = ;         var idFrom : Integer = GetIntValueByName('Tag');
      [*] = ;
      [*] = ;         if (gInternetShell.selsessionid=idFrom) then
      [*] = ;         gInternetShell.selsessionid := 0;
      [*] = ;
      [*] = ;         if (idFrom<>0) then
      [*] = ;         begin
      [*] = ;            var pClient : Integer = _parser_ParserTemporary(True);
      [*] = ;            if (LanPublicServerGetClientInfoToParserByClientID(idFrom, pClient)) then
      [*] = ;            begin
      [*] = ;               var p : Pointer = gInternetShell.clients.AddOrUpdateFromParser(pClient);
      [*] = ;               // this info is not valid in pClient yet, but it should be like this
      [*] = ;               TInternetShellClient(p).states.bplay := False;
      [*] = ;               TInternetShellClient(p).states.bmaster := False;
      [*] = ;               TInternetShellClient(p).states.bsession := False;
      [*] = ;            end;
      [*] = ;         end;
      [*] = ;         if (not gInternetShell.bshowroom) then
      [*] = ;         gbool_gui_showinternetshell := True;
      [*] = ;      end;
      [*] = ;      leShellServerInfo : begin
      [*] = ;         LogEvent('leShellServerInfo');
      [*] = ;         var pLan : Integer = LanSelectParser;
      [*] = ;         if (pLan<>0) then
      [*] = ;         begin
      [*] = ;            var core : String = ParserGetValueByKeyByHandle(pLan, 'core');
      [*] = ;            var data : String = ParserGetValueByKeyByHandle(pLan, 'data');
      [*] = ;            Log('current = '+GetBuildVersion+' srvdata = '+data+' srvcore = '+core);
      [*] = ;            if (data<>GetBuildVersion) then
      [*] = ;            begin
      [*] = ;               gInternetShell.prevstate := -1;
      [*] = ;               LanShutdown;
      [*] = ;            end;
      [*] = ;         end;
      [*] = ;      end;
      [*] = ;      else ErrorLog('unhandled lan event=' + IntToStr(gLanEvent));
      [*] = ;   end;
      [*] = ;end
      [*] = ;else
      [*] = ;ErrorLog('OnLanEvent and not IsLanPublicServerMode lanevent='+IntToStr(gLanEvent));
   struct.end
section.end

