section.begin
   Name = EventConnectStateMessage
   Code : struct.begin
      [*] = ;var elmHnd : Integer = GetIntValueByName('ElementHandle');
      [*] = ;var press : String = GetValueByName('Press');
      [*] = ;var tag : Integer = GetIntValueByName('Tag');
      [*] = ;
      [*] = ;const currentstatename = 'EventConnectStateMessage';
      [*] = ;var elmname, showstate, eventstate : String;
      [*] = ;_misc_GetGUIShowEventStateNames(currentstatename, elmname, showstate, eventstate);
      [*] = ;
      [*] = ;const cTagDisconnect = 102;
      [*] = ;const cTagModsSyncApprove = 110;
      [*] = ;
      [*] = ;if (press='c') then
      [*] = ;begin
      [*] = ;   case tag of
      [*] = ;      gc_gui_event_tagShow : ExecuteState(showstate);
      [*] = ;      gc_gui_event_tagHide : begin
      [*] = ;         _gui_SetGUIElementVisibleByName(elmname, False);
      [*] = ;      end;
      [*] = ;      gc_gui_event_tagClose{, gc_gui_hotkey_btnEnter}, gc_gui_hotkey_btnEscape : begin
      [*] = ;         _gui_SetGUIElementVisibleByName(elmname, False);
      [*] = ;         case gConnectState of
      [*] = ;            gc_ConnectState_Error, gc_ConnectState_Disconnect : begin
      [*] = ;               if (gInterface.gamemode=gc_gamemode_game) or (gInterface.gamemode=gc_gamemode_spectator) then
      [*] = ;               begin
      [*] = ;                  _misc_Surrender(True);
      [*] = ;                  _gui_SetGUIElementVisibleByName(elmname, False);
      [*] = ;                  gInterface.gamemode := gc_gamemode_mainmenu;
      [*] = ;                  _gui_InitShowMainMenu(False);
      [*] = ;                  _player_ResetAllPlayers;
      [*] = ;                  gbool_gui_maxcameradist := True;
      [*] = ;                  SoundManagerUnloadAmbientThreads;
      [*] = ;                  gbool_gui_newmapfinished := True;
      [*] = ;                  gConnectTimer := 0;
      [*] = ;                  _profile_SaveAdviser; // check if it is different inside
      [*] = ;                  //gInternetShell.bauth := False; // after bad game log off public server
      [*] = ;                  NewMap(128, 128, 0);
      [*] = ;               end
      [*] = ;               else
      [*] = ;               _gui_InitShowMainMenu(True);
      [*] = ;            end;
      [*] = ;         end;
      [*] = ;      end;
      [*] = ;      cTagDisconnect : begin
      [*] = ;         _gui_SetGUIElementVisibleByName(elmname, False);
      [*] = ;         _gui_SendTagToState('EventMultiplayerLogin', gc_gui_hotkey_btnEscape);
      [*] = ;         _gui_SendTagToState('EventInternetShell', gc_gui_event_tagHide);
      [*] = ;         _gui_SendTagToState('EventCustomGame', gc_gui_event_tagHide);
      [*] = ;         _gui_SendTagToState('EventHistoricalBattle', gc_gui_event_tagHide);
      [*] = ;         _gui_SendTagToState('EventMultiplayerLogin', gc_gui_event_tagHide);
      [*] = ;         _gui_SendTagToState('EventModalMessage', gc_gui_event_tagHide);
      [*] = ;         _gui_SendTagToState('EventConnectStateMessage', gc_gui_event_tagHide);
      [*] = ;         _gui_SendTagToState('EventCreateJoinRoom', gc_gui_event_tagHide);
      [*] = ;         gstring_gui_connectserver := '';
      [*] = ;         gint_gui_connectserverstate := 0;
      [*] = ;         LanShutdown;
      [*] = ;      end;
      [*] = ;      cTagModsSyncApprove : begin
      [*] = ;         var pSyncs : Integer = _parser_ParserModsSync(False);
      [*] = ;         if (pSyncs<>0) then
      [*] = ;         begin
      [*] = ;            if not SteamIsWorkshopPrepared then
      [*] = ;            SteamPrepareWorkshop(false, true);
      [*] = ;            if SteamIsWorkshopPrepared then
      [*] = ;            begin
      [*] = ;               LanShutdown;
      [*] = ;               _gui_ShowConnectStateMessage(gc_ConnectModsState_SyncInProgress);
      [*] = ;               SteamWorkshopCallback(StateMachineGetGUISMHandle, '', '', '', '', 'onworkshopautoupdate');
      [*] = ;
      [*] = ;               // save my previous mod list start
      [*] = ;               var restorefile : String = GetAppSaveDirectoryPath+'mods.restore';
      [*] = ;               var brestoreexists : Boolean = IsFileExists(restorefile);
      [*] = ;               var pModList : Integer = _parser_ParserTemporary(True);
      [*] = ;               if (not brestoreexists) then
      [*] = ;               ModLibraryGetParser(pModList, False)
      [*] = ;               else
      [*] = ;               ParserLoadFromFileByHandle(pModList, restorefile);
      [*] = ;               var pModListTemp : Integer = ParserAddChildByIndex(pModList, gc_parsername_tmp);
      [*] = ;               ParserSetValueByKeyByHandle(pModListTemp, 'checksum', StringRegister7);
      [*] = ;               ParserSaveToFileByHandle(pModList, GetAppSaveDirectoryPath+'mods.restore');
      [*] = ;               // save finish
      [*] = ;
      [*] = ;               if SteamSyncWorkshopItems(pSyncs)=0 then
      [*] = ;               ExecuteState('onworkshopautoupdate');
      [*] = ;            end
      [*] = ;            else
      [*] = ;            begin
      [*] = ;               _gui_SetGUIElementVisibleByName(elmname, False);
      [*] = ;               ErrorLog('EventConnectStateMessage : SteamIsWorkshopPrepared = False');
      [*] = ;            end;
      [*] = ;         end
      [*] = ;         else
      [*] = ;         begin
      [*] = ;            _gui_SetGUIElementVisibleByName(elmname, False);
      [*] = ;            ErrorLog('EventConnectStateMessage : mod sync parser handle = 0');
      [*] = ;         end;
      [*] = ;      end;
      [*] = ;   end;
      [*] = ;end;
   struct.end
section.end

