# Author: Yisc[NL] # # Lapper version needed: 7.0.4.9 or above # # # # Schedule V1.01 12-02-12 -Initial release # # Schedule V1.02 20-02-12 -Added multiple server options # # Schedule V1.03 25-02-12 -Polished loading code # # Schedule V1.03b 26-02-12 -Fixed a minor bug in close # # Schedule V1.04 22-04-13 -Auto load track/car(s) on Lapper start # # Schedule V1.04b 07-05-14 -? # # Schedule V1.05 21-01-15 -Auto load handicaps on Lapper start # # Schedule V1.05b 24-01-15 -Added loading of value use_subclasses # # Schedule V1.06 11-09-17 -Added RegisterScheduledAction # # Schedule V2.00.0 ALPHA 24-09-17 -Re-write for more efficient code # # Schedule V2.00.1 BETA 06-10-17 -Program is feature complete, tested as much as possible, time to gather feedback and fix reported bugs/issues # # Schedule V2.00.2 BETA 07-10-17 -Fixed a bug in calculating the UTC time from the local time # # -Added 'standard race password' # # Schedule V2.00.3 BETA 08-10-17 -Corrected some typos in comments # # -Changed and clarified the GlobalMsg when announcement about and actual checking of schedule is postponed # # -Added extra check to see wether event on the current day has already ended or not # # Schedule V2.00.4 BETA 08-10-17 -Fixed a bug in Sub 'ORS_OnLapperStart_Schedule' when settings should be changed 1 hour before start of event # # -Fixed a bug in Sub 'Schedule_trackcheck' when settings should be changed 1 hour before start of event # # Schedule V2.00.5 BETA 09-10-17 -Added extra check to prevent Lapper trying to register a ScheduledAction with an invalid syntax # # Schedule V2.00.6 BETA 10-10-17 -Added extra check to see if ending race is needed to change track and/or weather # # Schedule V2.00.7 BETA 11-10-17 -Added code to check for and if found, load handicap settings # # -Moved the checking/changing of the weather into a new Sub, to be executed after 10 seconds (due to loading track) # # -Made the columns for ID and More >>> a bit smaller # # -Made the column for Comment a bit bigger # # Schedule V2.00.8 BETA 13-10-17 -Fixed a bug where the track was never cleared for driving, because of no event having been found in the schedule # # -Added a button to show how long it will take when schedule will be checked (only on Lapper start) # # -Added a button to show how long it will take when weather setting will be checked # # Schedule V2.00.9 BETA 17-10-17 -Current qualify length is now checked and only changed if needed (needs LFS Lapper 7.0.4.9) # # -Current canreset status is now checked and only changed if needed (needs LFS Lapper 7.0.4.9) # # -Current cruise status is now checked and only changed if needed (needs LFS Lapper 7.0.4.9) # # Schedule V2.00.10 BETA 22-10-17 -Added two Globalvars to be used to write data to a file # # -Added a Goto to Sub 'OnNewPlayerJoin_Schedule' # # -Added a new Sub 'Update_password' to be able to save data to a file when a player joins the track # # Schedule V2.00.11 BETA 23-10-17 -Added an extra delay after ending a race (/end) (which takes at least 3 seconds), before changing track # # -Clear the values of GlobalVars $date_storage and $pwd_storage in Sub 'Update_password' after sending data through HTTP # # Schedule V2.00.12 BETA 23-10-17 -Fixed a bug regarding data storage which failed when no race was found during daily/hourly schedule check # # -Added join_track block to daily/hourly schedule check # # Schedule V2.00.13 BETA 24-10-17 -Added extra delay in Sub 'end_of_event' to be able to change track (if needed) at end of event # # Schedule V2.00.14 BETA 28-10-17 -Only go from Sub 'OnNewPlayerJoin_Schedule' to Sub 'Update_password' if $join_track_allowd is 'true' # # Schedule V2.01 31-10-17 -Moved the version out of BETA # # Schedule V2.02 31-10-17 -Fixed a bug in Sub 'Set_server_settings' which didn't check if Canreset needed changing when compared to General settings # # Schedule V2.03 17-12-17 -Fixed a bug in Sub 'Schedule' where UTC was calculated by adding(+) hours to local time, instead of substracting(-) hours from local time # # -Fixed a bug in Sub 'Schedule' where Hours were displayed as 24 instead of 00 # # -Fixed a bug in Sub 'Schedule_trackcheck' where Hours were displayed as 24 instead of 00 # # Schedule V2.04 09-04-18 -Added code to be able to change layout if needed # # Schedule V2.05 21-04-18 -Added code to be able to set the amount of splits of a layout (max = 4 , finishline has to be counted as split) # # Schedule V2.06 22-04-18 -Added code to be able to set race length in hours (1-48) # # Schedule V2.07 25-08-18 -Added code to set default server password when no scheduled race has been found on Lapper start # # Schedule V2.08 30-08-18 -Added code to set default server password when no scheduled race has been found on Daily/hourly check # # Schedule V2.09 29-03-21 -Added code to set to dectect Lapper date settings (using 2 or 4 digits for the year) and act accordingly # ################################################################################################################################################################################################# CatchEvent OnLapperStart() DelayedCommand( 1, notify_players_about_schedule_check ); DelayedCommand( 16, ORS_OnLapperStart_Schedule ); EndCatchEvent CatchEvent OnNewPlayerJoin( $userName ) # Player event OnNewPlayerJoin_Schedule(); EndCatchEvent CatchEvent OnMSO( $userName, $text ) # Player event $idxOfFirtsSpace = indexOf( $text, " "); IF( $idxOfFirtsSpace == -1 ) THEN $command = $text; $argv = ""; ELSE $command = subStr( $text,0,$idxOfFirtsSpace ); $argv = trim( subStr( $text,$idxOfFirtsSpace ) ); ENDIF SWITCH( $command ) CASE "!schedule": SetCurrentPlayerVar( "more_options_schedule" , "no" ); Schedule( $KeyFlags ); BREAK; ENDSWITCH EndCatchEvent Sub notify_players_about_schedule_check() openGlobalButton( "schedule_check",55,98,90,10,5,15,16,"^7Time left before schedule is checked: %cpt%", ); EndSub Sub ORS_OnLapperStart_Schedule() ### Get StoredValue 'SCHDL_CHECK_RSA' from the database and split it into an array using the spaces as splitting character ### ### Check if '$schedule_splitted' isn't empty, otherwise throw message about it on the Lapper console ### ### Get minute from arrayvalue 1 and reduce it by 1 minute ### ### In case $track_check_minute goes below zero, add 60 to its value ### ### Compile the new string for creating a Registered Scheduled Action ### IF ( GetStoredValue( "SCHDL_CHECK_RSA" ) != "" ) THEN $schedule_splitted = SplitToArray( GetStoredValue( "SCHDL_CHECK_RSA" )," " ); $track_check_minute = $schedule_splitted[1]-1; $track_check_hour = $schedule_splitted[2]; IF ( $track_check_minute < 0 ) THEN $track_check_minute = $track_check_minute + 60; IF ( $track_check_hour != "*" ) THEN $track_check_hour = $schedule_splitted[2]-1; IF ( $track_check_hour < 0 ) THEN $track_check_hour = $track_check_hour + 24; ENDIF ENDIF ENDIF $track_check_schedule = $schedule_splitted[0]." ".$track_check_minute." ".$track_check_hour." ".$schedule_splitted[3]." ".$schedule_splitted[4]." ".$schedule_splitted[5]." ".$schedule_splitted[6]; ### End ### ### Register two scheduled actions for both Track_check (announcement that check will happen in one minute and Schedule_trackcheck (actual check and changes if needed) ### ### Syntax: ss mm hh dayofweek dd MM YYYY ### RegisterScheduleAction( "check_track","" . $track_check_schedule, Track_check ); RegisterScheduleAction( "check_schedule","" . GetStoredValue( "SCHDL_CHECK_RSA" ), Schedule_trackcheck ); ### End ### ELSE writeline ( "" ); writeline ( "! WARNING !" ); writeline ( "" ); writeline ( "StoredValue 'SCHDL_CHECK_RSA' hasn't been found in the database" ); writeline ( "Therefor no ScheduledActions could be registered" ); writeline ( "Fill in all options of the General Configuration Screen" ); writeline ( "Then restart Lapper using: !reload" ); writeline ( "" ); writeline ( "" ); ENDIF ### End ### ### Declare global variables and give them a value ### GlobalVar $schedule_version; $schedule_version = "V2.09"; GlobalVar $race_number; GlobalVar $console_text; GlobalVar $join_track_allowed; $join_track_allowed="false"; GlobalVar $event_found; $event_found="no"; GlobalVar $date_storage; GlobalVar $pwd_storage; ### End ### ### Set server_name and storage_name ### IF ($server_name_schedule == "") THEN $server_name_schedule = StripLFSColor( getLapperVar( "HostName" ) ); ENDIF $storage_name = "SCHEDULE_".$server_name_schedule."_"; ### End ### ### Load scheduled races for this server instance ### FOR ($race_number=1;$race_number<=14;$race_number=$race_number+1) IF ( GetStoredValue( $storage_name . "date_" . $race_number ) != "" ) THEN $date_schedule_array[1,$race_number] = GetStoredValue( $storage_name . "date_" . $race_number ); ENDIF ENDFOR ### End ### ### Count number of values in array 'values_array_dates' $values_array_dates = arrayCount ( $date_schedule_array ); ### End ### ### Get current year,month,day ### IF ( strlen ( getLapperVar( "ShortDate" ) ) == 8 ) THEN $year = subStr( getLapperVar( "ShortDate" ), 6, 2); ELSE IF ( strlen ( getLapperVar( "ShortDate" ) ) == 10 ) THEN $year = subStr( getLapperVar( "ShortDate" ), 8, 2); ENDIF ENDIF $month = subStr( getLapperVar( "ShortDate" ), 3 , 2); $day = subStr( getLapperVar( "ShortDate" ), 0 , 2); ### END ### FOR ($race_number=1;$race_number<=$values_array_dates;$race_number=$race_number+1) $year_schdl = subStr( $date_schedule_array[1,$race_number], 6, 2); $month_schdl = subStr( $date_schedule_array[1,$race_number], 3 , 2); $day_schdl = subStr( $date_schedule_array[1,$race_number], 0 , 2); IF ($year_schdl == $year) THEN IF ($month_schdl == $month) THEN IF ($day_schdl == $day) THEN IF ( GetStoredValue( "SCHDL_CHANGE") == "Day of event" ) THEN ### Get current time and extract curren Hour and Minutes from it (converting Hour to 24-hour format if needed) ### $CurrTime = getLapperVar( "ShortTime" ); IF( subStr( $CurrTime, 1, 1) == ":" ) THEN $Hour = subStr( $CurrTime, 0, 1); $Minutes = subStr( $CurrTime, 2 , 2); IF( subStr( $CurrTime, 5 , 2) == "PM" ) THEN IF ( ToNum ($Hour) < 12 ) THEN $Hour=$Hour+12; ENDIF ENDIF ELSE $Hour = subStr( $CurrTime, 0, 2); $Minutes = subStr( $CurrTime, 3 , 2); IF( subStr( $CurrTime, 6 , 2) == "PM" ) THEN IF ( ToNum ($Hour) < 12 ) THEN $Hour=$Hour+12; ENDIF ENDIF ENDIF ### End ### ### Get Hour and Minutes from the upcoming event ### $Hour_event = SubStr ( GetStoredValue( $storage_name . "time_" . $race_number ) , 0 ,2 ); $Minutes_event = SubStr ( GetStoredValue( $storage_name . "time_" . $race_number ) , 3 ,2 ); ### End ### IF ( $Hour < $Hour_event ) THEN Set_server_settings ( $KeyFlags,"autol_today_" . $race_number ); $event_found="yes"; BREAK; ELSE IF ( $Hour == $Hour_event && $Minutes <= $Minutes_event ) THEN Set_server_settings ( $KeyFlags,"autol_today_" . $race_number ); $event_found="yes"; BREAK; ENDIF ENDIF ELSE IF ( GetStoredValue( "SCHDL_CHANGE") == "1 hour before event" ) THEN ### Get current time and extract curren Hour and Minutes from it (converting Hour to 24-hour format if needed) ### $CurrTime = getLapperVar( "ShortTime" ); IF( subStr( $CurrTime, 1, 1) == ":" ) THEN $Hour = subStr( $CurrTime, 0, 1); $Minutes = subStr( $CurrTime, 2 , 2); IF( subStr( $CurrTime, 5 , 2) == "PM" ) THEN IF ( ToNum ($Hour) < 12 ) THEN $Hour=$Hour+12; ENDIF ENDIF ELSE $Hour = subStr( $CurrTime, 0, 2); $Minutes = subStr( $CurrTime, 3 , 2); IF( subStr( $CurrTime, 6 , 2) == "PM" ) THEN IF ( ToNum ($Hour) < 12 ) THEN $Hour=$Hour+12; ENDIF ENDIF ENDIF ### End ### ### Get Hour and Minutes from the upcoming event ### $Hour_event = SubStr ( GetStoredValue( $storage_name . "time_" . $race_number ) , 0 ,2 ); $Minutes_event = SubStr ( GetStoredValue( $storage_name . "time_" . $race_number ) , 3 ,2 ); ### End ### IF ( $Hour == $Hour_event && $Minutes <= $Minutes_event ) THEN Set_server_settings ( $KeyFlags,"autol_1hour_" . $race_number ); $event_found="yes"; BREAK; ELSE IF ( $Hour+1 == $Hour_event && $Minutes <= $Minutes_event ) THEN Set_server_settings ( $KeyFlags,"autol_1hour_" . $race_number ); $event_found="yes"; BREAK; ENDIF ENDIF ENDIF ENDIF ENDIF IF ($day_schdl > $day) THEN IF ( GetStoredValue( "SCHDL_CHANGE") == "Day of event" ) THEN Set_server_settings ( $KeyFlags,"autol_0hour_" . $race_number ); $event_found="yes"; BREAK; ENDIF ENDIF ENDIF IF ($month_schdl > $month) THEN IF ( GetStoredValue( "SCHDL_CHANGE") == "Day of event" ) THEN Set_server_settings ( $KeyFlags,"autol_0hour_" . $race_number ); $event_found="yes"; BREAK; ENDIF ENDIF ENDIF IF ($year_schdl > $year) THEN IF ( GetStoredValue( "SCHDL_CHANGE") == "Day of event" ) THEN Set_server_settings ( $KeyFlags,"autol_0hour_" . $race_number ); $event_found="yes"; BREAK; ENDIF ENDIF ENDFOR ### When no event is found, clear the track for driving ### IF ( $event_found == "no" ) THEN GlobalMsg ( "^7Lapper start - No scheduled race found" ); $server_name_schedule = StripLFSColor( getLapperVar( "HostName" ) ); $storage_name = "SCHEDULE_".$server_name_schedule."_"; cmdLFS("/pass " . GetStoredValue( $storage_name . "DEF_PWD" ) ); GlobalMsg ( "^7Lapper start - Default server password has been set" ); $join_track_allowed="true"; ENDIF ### End ### EndSub Sub Set_server_settings ( $KeyFlags,$id ) $method = SubStr ( $id , 0 , 5); $action = SubStr ( $id , 6 , 5); $race_number = SubStr ( $id , 12 , 2); IF ( $method == "autol" ) THEN $console_text="Auto load "; ELSE $console_text="Checked load "; ENDIF ### Set server_name and storage_name ### IF ($server_name_schedule == "") THEN $server_name_schedule = StripLFSColor( getLapperVar( "HostName" ) ); ENDIF $storage_name = "SCHEDULE_".$server_name_schedule."_"; ### End ### writeline ( "" ); writeline ( "" ); writeline ( "---------------".$console_text."start-------------------" ); writeline( $console_text . StripLFSColor( $server_name_schedule ) ); writeline( $console_text . GetStoredValue( $storage_name . "date_" . $race_number ) . " - " . GetStoredValue( $storage_name . "time_" . $race_number ) ); writeline ( "" ); IF ( getLapperVar( "ShortTrackName" ) != GetStoredValue( $storage_name . "track_" . $race_number ) ) THEN cmdLFS("/end"); writeline( $console_text."Race ended, track change needed" ); ### Set a 8 second DelayedCommand to change track ### ### Ending a race takes 3 seconds, then wait an extra 5 seconds before changing track ### DelayedCommand( 8, change_track_schedule ); openGlobalButton( "track_change",55,87,90,10,5,8,16,"^7Time left before track is changed: %cpt%", ); ### End ### ENDIF ### Set a 16 second DelayedCommand to change layout if trackcode ends on X or Y ### IF ( SubStr( GetStoredValue( $storage_name . "track_" . $race_number ),3,1 ) == "X" || SubStr( GetStoredValue( $storage_name . "track_" . $race_number ),3,1 ) == "Y" || SubStr( GetStoredValue( $storage_name . "track_" . $race_number ),4,1 ) == "X" || SubStr( GetStoredValue( $storage_name . "track_" . $race_number ),4,1 ) == "Y" ) THEN DelayedCommand( 16, change_layout_schedule ); ENDIF ### End ### IF ( getLapperVar( "allowedcars" ) != GetStoredValue( $storage_name . "cars_" . $race_number ) ) THEN IF ( GetStoredValue( $storage_name . "cars_" . $race_number ) != "" ) THEN cmdLFS("/cars " . GetStoredValue( $storage_name . "cars_" . $race_number ) ); writeline( $console_text."Car(s) changed" ); ENDIF ENDIF IF ( getLapperVar( "racelaps" ) != GetStoredValue( $storage_name . "laps_" . $race_number ) ) THEN IF ( GetStoredValue( $storage_name . "laps_" . $race_number ) != "" ) THEN IF ( subStr( GetStoredValue( $storage_name . "laps_" . $race_number ), 0, 1 ) == "H" ) THEN $hours = subStr( GetStoredValue( $storage_name . "laps_" . $race_number ), 1, 2 ); IF ( getLapperVar( "racehours" ) != $hours ) THEN cmdLFS("/hours " . $hours ); writeline( $console_text."Hours changed" ); ENDIF ELSE cmdLFS("/laps " . GetStoredValue( $storage_name . "laps_" . $race_number ) ); writeline( $console_text."Laps changed" ); ENDIF ENDIF ENDIF IF ( getLapperVar( "wind" ) != GetStoredValue( $storage_name . "wind_" . $race_number ) ) THEN IF ( GetStoredValue( $storage_name . "wind_" . $race_number ) != "" ) THEN cmdLFS("/wind " . GetStoredValue( $storage_name . "wind_" . $race_number ) ); writeline( $console_text."Wind changed" ); ENDIF ENDIF ### Set a 26 second DelayedCommand to check and if needed, change weather ### ### This because the loading of the track takes a while and weather can only be changed once track is loaded ### DelayedCommand( 26, change_weather_schedule ); openGlobalButton( "weather_change",55,98,90,10,5,26,16,"^7Time left before weather setting is checked: %cpt%", ); ### End ### IF ( $action == "today" || $action == "1hour" ) THEN IF ( getLapperVar ( "qualmins" ) != GetStoredValue( $storage_name . "qual_" . $race_number ) ) THEN IF ( GetStoredValue( $storage_name . "qual_" . $race_number ) != "" ) THEN cmdLFS ( "/qual " . GetStoredValue( $storage_name . "qual_" . $race_number ) ); writeline( $console_text."Qual length (event) changed" ); ENDIF ENDIF ELSE IF ( getLapperVar ( "qualmins" ) != 240 ) THEN cmdLFS ( "/qual 240" ); writeline( $console_text."Qual length (regular) changed" ); ENDIF ENDIF IF ( $action == "today" || $action == "1hour" ) THEN IF ( GetStoredValue( $storage_name . "event_pwd_" . $race_number ) != "" ) THEN cmdLFS("/pass " . GetStoredValue( $storage_name . "event_pwd_" . $race_number ) ); writeline( $console_text."Password (event) changed" ); ENDIF ELSE cmdLFS("/pass " . GetStoredValue( $storage_name . "regular_pwd_" . $race_number ) ); writeline( $console_text."Password (regular) changed" ); ENDIF ### Set GlobalVar $date_storage and $pwd_storage to be able to send them through the HTTP-function in Sub 'Update_password' ### $date_storage = GetStoredValue( $storage_name . "date_" . $race_number ); $pwd_storage = GetStoredValue( $storage_name . "event_pwd_" . $race_number ); ### End ### ### Get current reset status (0 = No = Not allowed , 1 = Yes = Allowed ### $canreset = getLapperVar ( "canreset" ); IF ( $canreset == 0 ) THEN $canreset = "No"; ELSE IF ( $canreset == 1 ) THEN $canreset = "Yes"; ENDIF ENDIF ### End ### IF ( $action == "today" || $action == "1hour" ) THEN IF ( $canreset != GetStoredValue( $storage_name . "reset_" . $race_number ) ) THEN IF ( GetStoredValue( $storage_name . "reset_" . $race_number ) != "" ) THEN cmdLFS("/canreset " . GetStoredValue( $storage_name . "reset_" . $race_number ) ); writeline( $console_text."Can reset (event) changed" ); ENDIF ENDIF ELSE IF ( $canreset != GetStoredValue( "SCHDL_GENERAL_RESET" ) ) THEN cmdLFS("/canreset " . GetStoredValue( "SCHDL_GENERAL_RESET" ) ); writeline( $console_text."Can reset (general) changed" ); ENDIF ENDIF ### Get current cruise status (0 = No = Not allowed , 1 = Yes = Allowed ### $cruise = getLapperVar ( "cruise" ); IF ( $cruise == 0 ) THEN $cruise = "No"; ELSE IF ( $cruise == 1 ) THEN $cruise = "Yes"; ENDIF ENDIF ### End ### IF ( GetStoredValue( $storage_name . "cruise_" . $race_number ) != "" ) THEN IF ( $cruise != GetStoredValue( $storage_name . "cruise_" . $race_number ) ) THEN cmdLFS("/cruise " . GetStoredValue( $storage_name . "cruise_" . $race_number ) ); writeline( $console_text."Cruise allowed changed" ); ENDIF ENDIF ### Check wether there are handicap settings that needs to be loaded ### $race_id_handicaps = GetStoredValue( $storage_name . "race_id_" . $race_number ); $storage_name_hcs = "HCS_".$race_id_handicaps."_"; IF ( GetStoredValue( $storage_name_hcs . "main_settings" ) != "" ) THEN $main_settings = SplitToArray ( GetStoredValue( $storage_name_hcs . "main_settings" ),"*" ); $class_indicator = $main_settings[0]; $use_subclasses = $main_settings[1]; $number_of_classes = $main_settings[2]; $number_of_cars = $main_settings[3]; writeline( $console_text."Handicap settings found and loaded" ); ELSE $race_id_handicaps=""; ENDIF ### End ### EndSub Sub change_track_schedule() ### Set server_name and storage_name ### IF ($server_name_schedule == "") THEN $server_name_schedule = StripLFSColor( getLapperVar( "HostName" ) ); ENDIF $storage_name = "SCHEDULE_".$server_name_schedule."_"; ### End ### IF ( getLapperVar( "ShortTrackName" ) != GetStoredValue( $storage_name . "track_" . $race_number ) ) THEN IF ( GetStoredValue( $storage_name . "track_" . $race_number ) != "" ) THEN cmdLFS("/track " . GetStoredValue( $storage_name . "track_" . $race_number ) ); writeline( $console_text."Track changed" ); ENDIF ENDIF EndSub Sub change_layout_schedule() ### Set server_name and storage_name ### IF ($server_name_schedule == "") THEN $server_name_schedule = StripLFSColor( getLapperVar( "HostName" ) ); ENDIF $storage_name = "SCHEDULE_".$server_name_schedule."_"; ### End ### IF ( GetStoredValue( $storage_name . "layout_" . $race_number ) != "" ) THEN cmdLFS("/axload " . GetStoredValue( $storage_name . "layout_" . $race_number ) ); writeline( $console_text."Layout changed" ); $number_of_splits = GetStoredValue( $storage_name . "splits_" . $race_number ); writeline( $console_text."Number of splits set to ".$number_of_splits ); ENDIF EndSub Sub change_weather_schedule() ### Set server_name and storage_name ### IF ($server_name_schedule == "") THEN $server_name_schedule = StripLFSColor( getLapperVar( "HostName" ) ); ENDIF $storage_name = "SCHEDULE_".$server_name_schedule."_"; ### End ### IF ( getLapperVar( "weather" ) != GetStoredValue( $storage_name . "weather_" . $race_number ) ) THEN IF ( GetStoredValue( $storage_name . "weather_" . $race_number ) != "" ) THEN cmdLFS("/end"); writeline( $console_text."Race ended, weather change needed" ); cmdLFS("/weather " . GetStoredValue( $storage_name . "weather_" . $race_number ) ); writeline( $console_text."Weather changed" ); ENDIF ENDIF ### Create settings for DefaultTopCar ### ### Allow players to join track ### setConfigVar( DefaultTopCar, GetStoredValue( $storage_name . "cars_" . $race_number ) ); $join_track_allowed="true"; ### End ### writeline ( "---------------".$console_text."finish------------------" ); writeline ( "" ); writeline ( "" ); EndSub Sub Schedule ( $KeyFlags ) ### Set server_name and storage_name ### IF ( GetCurrentPlayerVar( "server_name_schedule" ) == "" ) THEN SetCurrentPlayerVar( "server_name_schedule", StripLFSColor( getLapperVar( "HostName" ) ) ); ENDIF SetCurrentPlayerVar( "storage_name_schdl" , "SCHEDULE_" . GetCurrentPlayerVar( "server_name_schedule" ) ."_" ); ### End ### ### Set initial values for left/right and top/bottom coordinates ### $left_right_schedule = 1; $top_bottom_schedule = 30; ### End ### ### Draw the Schedule GUI ### openPrivButton( "schedule_gui_bg",$left_right_schedule,$top_bottom_schedule,162,123,5,-1,16,""); openPrivButton( "schedule_title",$left_right_schedule+1,$top_bottom_schedule+1,80,5,5,-1,32,"^7Schedule system " . $schedule_version ); openPrivButton( "schedule_server_name",$left_right_schedule+81,$top_bottom_schedule+1,80,5,5,-1,32,"^7Server name: " . getLapperVar( "HostName" ) ); FOR ($server=1;$server<=8;$server=$server+1) ### Set left/right coordinate based on which server will be displayed ### IF ( $server == 2 || $server == 4 || $server == 6 || $server == 8 ) THEN $left_right_schedule = 84; ELSE $left_right_schedule = 1; ENDIF ### End ### ### Retrieve server name from database ### $server_name = StripLFSColor( GetStoredValue( "SCHDL_SERVER_NAME_".$server ) ); $server_name_display = GetStoredValue( "SCHDL_SERVER_NAME_".$server ); ### End ### IF ( $server_name != "" ) THEN openPrivButton( "schedule_server_name_" . $server,$left_right_schedule+1,$top_bottom_schedule+11,20,5,5,-1,32,"^7Server name " . $server .":" ); openPrivButton( "schedule_server_name_input_" . $server,$left_right_schedule+21,$top_bottom_schedule+11,42,5,5,-1,32,"^3".$server_name_display ); ENDIF IF ( $server_name == GetCurrentPlayerVar( "server_name_schedule" ) ) THEN openPrivButton( "schedule_server_name_activate_" . $server,$left_right_schedule+63,$top_bottom_schedule+11,15,5,5,-1,32,"^2LOADED" ); ELSE IF ( $server_name != "" ) THEN openPrivButton( "schedule_server_name_activate_" . $server,$left_right_schedule+63,$top_bottom_schedule+11,15,5,5,-1,32,"^3LOAD",load_server_name ); ENDIF ENDIF ### Raise top/bottom value by 5, after server 2/4/6 have been displayed ### IF ( $server == 2 || $server == 4 || $server == 6 ) THEN $top_bottom_schedule = $top_bottom_schedule + 5; ENDIF ### End ### ENDFOR ### Reset values for left/right and top/bottom coordinates ### $left_right_schedule = 1; $top_bottom_schedule = 35; ### End ### openPrivButton( "schedule_number",$left_right_schedule+1,$top_bottom_schedule+31,5,5,5,-1,32,"^7#" ); openPrivButton( "schedule_date",$left_right_schedule+6,$top_bottom_schedule+31,13,5,5,-1,32,"^7Date" ); openPrivButton( "schedule_time_local",$left_right_schedule+19,$top_bottom_schedule+31,15,5,5,-1,32,"^7Time local" ); openPrivButton( "schedule_time_utc",$left_right_schedule+34,$top_bottom_schedule+31,15,5,5,-1,32,"^7Time UTC" ); openPrivButton( "schedule_track",$left_right_schedule+49,$top_bottom_schedule+31,10,5,5,-1,32,"^7Track" ); IF ( GetCurrentPlayerVar( "more_options_schedule" ) == "no" ) THEN openPrivButton( "schedule_cars",$left_right_schedule+59,$top_bottom_schedule+31,35,5,5,-1,32,"^7Cars" ); openPrivButton( "schedule_laps",$left_right_schedule+94,$top_bottom_schedule+31,10,5,5,-1,32,"^7Laps" ); openPrivButton( "schedule_comment",$left_right_schedule+104,$top_bottom_schedule+31,41,5,5,-1,32,"^7Comment" ); openPrivButton( "schedule_race_id",$left_right_schedule+145,$top_bottom_schedule+31,5,5,5,-1,32,"^7ID:" ); openPrivButton( "schedule_more_options",$left_right_schedule+150,$top_bottom_schedule+31,11,5,5,-1,32,"^3More >>>",activate_more_options_schedule ); ENDIF IF ( GetCurrentPlayerVar( "more_options_schedule" ) == "yes" ) THEN openPrivButton( "schedule_weather",$left_right_schedule+59,$top_bottom_schedule+31,12,5,5,-1,32,"^7Weather:" ); openPrivButton( "schedule_wind",$left_right_schedule+71,$top_bottom_schedule+31,10,5,5,-1,32,"^7Wind:" ); openPrivButton( "schedule_qual",$left_right_schedule+81,$top_bottom_schedule+31,10,5,5,-1,32,"^7Qual:" ); openPrivButton( "schedule_start",$left_right_schedule+91,$top_bottom_schedule+31,10,5,5,-1,32,"^7Start:" ); openPrivButton( "schedule_reset",$left_right_schedule+101,$top_bottom_schedule+31,10,5,5,-1,32,"^7Reset:" ); openPrivButton( "schedule_cruise",$left_right_schedule+111,$top_bottom_schedule+31,10,5,5,-1,32,"^7Cruise:" ); openPrivButton( "schedule_less_options",$left_right_schedule+121,$top_bottom_schedule+31,19,5,5,-1,32,"^3<<< Less",activate_less_options_schedule ); ENDIF $top_bottom_schedule = 71; ### Get current year, month and day ### IF ( strlen ( getLapperVar( "ShortDate" ) ) == 8 ) THEN $year = subStr( getLapperVar( "ShortDate" ), 6, 2); ELSE IF ( strlen ( getLapperVar( "ShortDate" ) ) == 10 ) THEN $year = subStr( getLapperVar( "ShortDate" ), 8, 2); ENDIF ENDIF $month = subStr( getLapperVar( "ShortDate" ), 3 , 2); $day = subStr( getLapperVar( "ShortDate" ), 0 , 2); ### End ### FOR ($race_number=1;$race_number<=14;$race_number=$race_number+1) ### If $race_number is below 10, add a leading zero ### IF ($race_number < 10) THEN $number="0".$race_number; ELSE $number=$race_number; ENDIF ### End ### ### When PlayerVar 'check_empty_row' reaches value 1, set PlayerVar 'data_check' to "not_okay" ### ### Then start to loop through the possible remaining number of race and look for a filled 'date' field ### ### If found one, set PlayerVar 'check_empty_row' to value 0 and BREAK out of the for-loop ### ### In case PlayerVar 'data_check' is still set at "not_okay" once the for-loop completed, then BREAK out of for-loop showing the scheduled races ### IF ( GetCurrentPlayerVar( "check_empty_row" ) == 1 ) THEN SetCurrentPlayerVar( "data_check" , "not_okay" ); FOR ($data_check=$race_number;$data_check<=14;$data_check=$data_check+1) IF ( GetStoredValue( GetCurrentPlayerVar( "storage_name_schdl" ) . "date_".$data_check ) != "" ) THEN SetCurrentPlayerVar( "data_check" , "okay" ); SetCurrentPlayerVar( "check_empty_row" , 0 ); BREAK; ENDIF ENDFOR IF ( GetCurrentPlayerVar( "data_check" ) == "not_okay" ) THEN BREAK; ENDIF ENDIF ### End ### IF ( GetStoredValue( GetCurrentPlayerVar( "storage_name_schdl" ) . "date_".$race_number ) != "" ) THEN $year_schdl = subStr( GetStoredValue( GetCurrentPlayerVar( "storage_name_schdl" ) . "date_".$race_number ), 6, 2); $month_schdl = subStr( GetStoredValue( GetCurrentPlayerVar( "storage_name_schdl" ) . "date_".$race_number ), 3 , 2); $day_schdl = subStr( GetStoredValue( GetCurrentPlayerVar( "storage_name_schdl" ) . "date_".$race_number ), 0 , 2); ### Get Hour, Minutes and Timezone from the upcoming event ### $Hour_event = SubStr ( GetStoredValue( GetCurrentPlayerVar( "storage_name_schdl" ) . "time_".$race_number ) , 0 ,2 ); $Minutes_event = SubStr ( GetStoredValue( GetCurrentPlayerVar( "storage_name_schdl" ) . "time_".$race_number ) , 3 ,2 ); $Timezone_event = SubStr ( GetStoredValue( GetCurrentPlayerVar( "storage_name_schdl" ) . "time_".$race_number ) , 6 ,4 ); ### End ### ### Get current time and extract current Hour and Minutes from it (converting Hour to 24-hour format if needed) ### $CurrTime = getLapperVar( "ShortTime" ); IF( subStr( $CurrTime, 1, 1) == ":" ) THEN $Hour = subStr( $CurrTime, 0, 1); $Minutes = subStr( $CurrTime, 2 , 2); IF( subStr( $CurrTime, 5 , 2) == "PM" ) THEN IF ( ToNum ($Hour) < 12 ) THEN $Hour=$Hour+12; ENDIF ENDIF ELSE $Hour = subStr( $CurrTime, 0, 2); $Minutes = subStr( $CurrTime, 3 , 2); IF( subStr( $CurrTime, 6 , 2) == "PM" ) THEN IF ( ToNum ($Hour) < 12 ) THEN $Hour=$Hour+12; ENDIF ENDIF ENDIF ### End ### IF ($year_schdl == $year) THEN IF ($month_schdl == $month) THEN IF ($day_schdl > $day) THEN $color="^7"; $color_button=32; ELSE IF ($day_schdl == $day) THEN ### Check if "SCHDL_EVENT_END" is set to 2 or 3 hours and set $hours_until_end_event accordingly. Otherwise set $hours_until_end_event to 0 ### IF ( GetStoredValue( "SCHDL_EVENT_END") == "After 2 hours" ) THEN $hours_until_end_event = 2; ELSE IF ( GetStoredValue( "SCHDL_EVENT_END") == "After 3 hours" ) THEN $hours_until_end_event = 3; ELSE $hours_until_end_event = 0; ENDIF ENDIF ### End ### ### Check if current Hour is below Hour_event + hours_until_end_event ### IF ( $Hour < $Hour_event + $hours_until_end_event ) THEN $color="^7"; $color_button=32; ELSE ### Check if current Hour is equal to Hour_event + hours_until_end_event and if current Minutes are below or equal to Minutes_event ### IF ( $Hour == $Hour_event + $hours_until_end_event && $Minutes <= $Minutes_event ) THEN $color="^7"; $color_button=32; ELSE $color="^8"; $color_button=16; ENDIF ### End ### ENDIF ### End ### ELSE $color="^8"; $color_button=16; ENDIF ENDIF ELSE IF ($month_schdl > $month) THEN $color="^7"; $color_button=32; ELSE $color="^8"; $color_button=16; ENDIF ENDIF ELSE IF ($year_schdl > $year) THEN $color="^7"; $color_button=32; ELSE $color="^8"; $color_button=16; ENDIF ENDIF openPrivButton( "schedule_number_".$race_number,$left_right_schedule+1,$top_bottom_schedule,5,5,5,-1,$color_button,$color . $number.": " ); openPrivButton( "schedule_date_".$race_number,$left_right_schedule+6,$top_bottom_schedule,13,5,5,-1,$color_button,$color . GetStoredValue( GetCurrentPlayerVar( "storage_name_schdl" ) . "date_".$race_number ) ); openPrivButton( "schedule_time_local_".$race_number,$left_right_schedule+19,$top_bottom_schedule,15,5,5,-1,$color_button,$color . GetStoredValue( GetCurrentPlayerVar( "storage_name_schdl" ) . "time_".$race_number ) ); ### Adjust hours based on found timezone and corresponding offset ### IF ( $Timezone_event == GetStoredValue( "SCHDL_TIMEZONE_1" ) ) THEN $Hour_event = $Hour_event - GetStoredValue( "SCHDL_TIMEZONE_1_OFFSET" ); ELSE IF ( $Timezone_event == GetStoredValue( "SCHDL_TIMEZONE_2" ) ) THEN $Hour_event = $Hour_event - GetStoredValue( "SCHDL_TIMEZONE_2_OFFSET" ); ENDIF ENDIF ### End ### ### In case adjusted hours is below 0 or above 24, recalculate them IF ( $Hour_event < 0 ) THEN $Hour_event = $Hour_event + 24; ENDIF IF ( $Hour_event > 24 ) THEN $Hour_event = $Hour_event - 24; ELSE IF ( $Hour_event == 24 ) THEN $Hour_event = 0; ENDIF ENDIF ### End ### ### Add leading zero in case $Hour_event is below 10 ### IF ( $Hour_event < 10 ) THEN $Hour_event="0".$Hour_event; ENDIF ### End ### $UTC_event = $Hour_event.":".$Minutes_event." UTC"; openPrivButton( "schedule_time_utc_".$race_number,$left_right_schedule+34,$top_bottom_schedule,15,5,5,-1,$color_button,$color . $UTC_event ); openPrivButton( "schedule_track_".$race_number,$left_right_schedule+49,$top_bottom_schedule,10,5,5,-1,$color_button,$color . GetStoredValue( GetCurrentPlayerVar( "storage_name_schdl" ) . "track_".$race_number ) ); IF ( GetCurrentPlayerVar( "more_options_schedule" ) == "no" ) THEN openPrivButton( "schedule_cars_".$race_number,$left_right_schedule+59,$top_bottom_schedule,35,5,5,-1,$color_button,$color . GetStoredValue( GetCurrentPlayerVar( "storage_name_schdl" ) . "cars_".$race_number ) ); openPrivButton( "schedule_laps_".$race_number,$left_right_schedule+94,$top_bottom_schedule,10,5,5,-1,$color_button,$color . GetStoredValue( GetCurrentPlayerVar( "storage_name_schdl" ) . "laps_".$race_number ) ); openPrivButton( "schedule_comment_".$race_number,$left_right_schedule+104,$top_bottom_schedule,41,5,5,-1,$color_button,$color . GetStoredValue( GetCurrentPlayerVar( "storage_name_schdl" ) . "comment_".$race_number ) ); openPrivButton( "schedule_race_id_".$race_number,$left_right_schedule+145,$top_bottom_schedule,5,5,5,-1,$color_button,$color . GetStoredValue( GetCurrentPlayerVar( "storage_name_schdl" ) . "race_id_".$race_number ) ); ELSE openPrivButton( "schedule_weather_".$race_number,$left_right_schedule+59,$top_bottom_schedule,12,5,5,-1,$color_button,$color . GetStoredValue( GetCurrentPlayerVar( "storage_name_schdl" ) . "weather_".$race_number ) ); openPrivButton( "schedule_wind_".$race_number,$left_right_schedule+71,$top_bottom_schedule,10,5,5,-1,$color_button,$color . GetStoredValue( GetCurrentPlayerVar( "storage_name_schdl" ) . "wind_".$race_number ) ); openPrivButton( "schedule_qual_".$race_number,$left_right_schedule+81,$top_bottom_schedule,10,5,5,-1,$color_button,$color . GetStoredValue( GetCurrentPlayerVar( "storage_name_schdl" ) . "qual_".$race_number ) ); openPrivButton( "schedule_start_".$race_number,$left_right_schedule+91,$top_bottom_schedule,10,5,5,-1,$color_button,$color . GetStoredValue( GetCurrentPlayerVar( "storage_name_schdl" ) . "start_".$race_number ) ); openPrivButton( "schedule_reset_".$race_number,$left_right_schedule+101,$top_bottom_schedule,10,5,5,-1,$color_button,$color . GetStoredValue( GetCurrentPlayerVar( "storage_name_schdl" ) . "reset_".$race_number ) ); openPrivButton( "schedule_cruise_".$race_number,$left_right_schedule+111,$top_bottom_schedule,10,5,5,-1,$color_button,$color . GetStoredValue( GetCurrentPlayerVar( "storage_name_schdl" ) . "cruise_".$race_number ) ); ENDIF $top_bottom_schedule=$top_bottom_schedule+5; ELSE SetCurrentPlayerVar( "check_empty_row" , GetCurrentPlayerVar( "check_empty_row" ) +1 ); ENDIF ENDFOR $top_bottom_schedule = 146; openPrivButton( "schedule_close",$left_right_schedule+1,$top_bottom_schedule+1,160,5,5,-1,32,"^3Close",schedule_close ); EndSub Sub load_server_name ( $KeyFlags,$id ) ### Find the server number by reading the ID of the clicked button, start on position 30 and read 1 character ### ### Retrieve server name from database and put server name into variable 'server_name_schedule', announce new server name, close buttons from previous schedule ### ### Re-open the set_schedule GUI ### $server_number = ToNum( subStr( $id, 30, 1 ) ); SetCurrentPlayerVar( "server_name_schedule" , StripLFSColor( GetStoredValue( "SCHDL_SERVER_NAME_".$server_number ) ) ); privMsg ( "^7Server name set to " . GetCurrentPlayerVar( "server_name_schedule" ) ); FOR ($race_number=1;$race_number<=14;$race_number=$race_number+1) closePrivButton( "schedule_server_name_" . $race_number ); closePrivButton( "schedule_server_name_input_" . $race_number) ; closePrivButton( "schedule_server_name_activate_" . $race_number ); ENDFOR schedule_close ( $KeyFlags,$id ); Schedule ( $KeyFlags ); EndSub Sub schedule_close ( $KeyFlags,$id ) closePrivButton( "schedule_gui_bg" ); closePrivButton( "schedule_title" ); closePrivButton( "schedule_server_name" ); closePrivButton( "schedule_number" ); closePrivButton( "schedule_date" ); closePrivButton( "schedule_time_local" ); closePrivButton( "schedule_time_utc" ); closePrivButton( "schedule_track" ); closePrivButton( "schedule_cars" ); closePrivButton( "schedule_laps" ); closePrivButton( "schedule_comment" ); closePrivButton( "schedule_race_id" ); closePrivButton( "schedule_weather" ); closePrivButton( "schedule_wind" ); closePrivButton( "schedule_qual" ); closePrivButton( "schedule_start" ); closePrivButton( "schedule_cruise" ); closePrivButton( "schedule_reset" ); closePrivButton( "schedule_more_options" ); closePrivButton( "schedule_less_options" ); FOR ($race_number=1;$race_number<=14;$race_number=$race_number+1) closePrivButton( "schedule_server_name_" . $race_number ); closePrivButton( "schedule_server_name_input_" . $race_number ); closePrivButton( "schedule_server_name_activate_" . $race_number ); closePrivButton( "schedule_number_" . $race_number ); closePrivButton( "schedule_date_" . $race_number ); closePrivButton( "schedule_time_local_" . $race_number ); closePrivButton( "schedule_time_utc_" . $race_number ); closePrivButton( "schedule_track_" . $race_number ); closePrivButton( "schedule_cars_" . $race_number ); closePrivButton( "schedule_laps_" . $race_number ); closePrivButton( "schedule_comment_" . $race_number ); closePrivButton( "schedule_race_id_" . $race_number ); closePrivButton( "schedule_weather_" . $race_number ); closePrivButton( "schedule_wind_" . $race_number ); closePrivButton( "schedule_qual_" . $race_number ); closePrivButton( "schedule_start_" . $race_number ); closePrivButton( "schedule_cruise_" . $race_number ); closePrivButton( "schedule_reset_" . $race_number ); ENDFOR IF ( $id == "schedule_close" ) THEN $server_name_schedule = ""; ENDIF closePrivButton("schedule_close"); EndSub Sub activate_more_options_schedule ( $KeyFlags,$id ) closePrivButton( "schedule_cars" ); closePrivButton( "schedule_laps" ); closePrivButton( "schedule_comment" ); closePrivButton( "schedule_race_id" ); closePrivButton( "schedule_more_options" ); FOR ($race_number=1;$race_number<=14;$race_number=$race_number+1) closePrivButton( "schedule_cars_" . $race_number ); closePrivButton( "schedule_laps_" . $race_number ); closePrivButton( "schedule_comment_" . $race_number ); closePrivButton( "schedule_race_id_" . $race_number ); ENDFOR SetCurrentPlayerVar( "more_options_schedule" , "yes" ); Schedule ( $KeyFlags ); EndSub Sub activate_less_options_schedule ( $KeyFlags,$id ) closePrivButton( "schedule_weather" ); closePrivButton( "schedule_wind" ); closePrivButton( "schedule_qual" ); closePrivButton( "schedule_start" ); closePrivButton( "schedule_reset" ); closePrivButton( "schedule_cruise" ); closePrivButton( "schedule_less_options" ); FOR ($race_number=1;$race_number<=14;$race_number=$race_number+1) closePrivButton( "schedule_weather_" . $race_number ); closePrivButton( "schedule_wind_" . $race_number ); closePrivButton( "schedule_qual_" . $race_number ); closePrivButton( "schedule_start_" . $race_number ); closePrivButton( "schedule_reset_" . $race_number ); closePrivButton( "schedule_cruise_" . $race_number ); ENDFOR SetCurrentPlayerVar( "more_options_schedule" , "no" ); Schedule ( $KeyFlags ); EndSub Sub Schedule_trackcheck () ### Set server_name and storage_name ### IF ($server_name_schedule == "") THEN $server_name_schedule = StripLFSColor( getLapperVar( "HostName" ) ); ENDIF $storage_name = "SCHEDULE_".$server_name_schedule."_"; ### End ### ### Load scheduled races for this server instance ### FOR ($race_number=1;$race_number<=14;$race_number=$race_number+1) IF ( GetStoredValue( $storage_name . "date_" . $race_number ) != "" ) THEN $date_schedule_array[1,$race_number] = GetStoredValue( $storage_name . "date_" . $race_number ); ENDIF ENDFOR ### End ### ### Count number of values in array 'values_array_dates' $values_array_dates = arrayCount ( $date_schedule_array ); ### End ### ### Get current Year,Month,Day ### IF ( strlen ( getLapperVar( "ShortDate" ) ) == 8 ) THEN $year = subStr( getLapperVar( "ShortDate" ), 6, 2); ELSE IF ( strlen ( getLapperVar( "ShortDate" ) ) == 10 ) THEN $year = subStr( getLapperVar( "ShortDate" ), 8, 2); ENDIF ENDIF $month = subStr( getLapperVar( "ShortDate" ), 3 , 2); $day = subStr( getLapperVar( "ShortDate" ), 0 , 2); ### END ### ### Set $join_track_allowed to value 'false' , set $event_found to value 'no' ### $join_track_allowed="false"; $event_found="no"; ### End ### FOR ($race_number=1;$race_number<=$values_array_dates;$race_number=$race_number+1) $year_schdl = subStr( $date_schedule_array[1,$race_number], 6, 2); $month_schdl = subStr( $date_schedule_array[1,$race_number], 3 , 2); $day_schdl = subStr( $date_schedule_array[1,$race_number], 0 , 2); IF ($year_schdl == $year) THEN IF ($month_schdl == $month) THEN IF ($day_schdl == $day) THEN IF ( GetStoredValue( "SCHDL_CHANGE") == "Day of event" ) THEN ### Get current time and extract current Hour and Minutes from it (converting Hour to 24-hour format if needed) ### $CurrTime = getLapperVar( "ShortTime" ); IF( subStr( $CurrTime, 1, 1) == ":" ) THEN $Hour = subStr( $CurrTime, 0, 1); $Minutes = subStr( $CurrTime, 2 , 2); IF( subStr( $CurrTime, 5 , 2) == "PM" ) THEN IF ( ToNum ($Hour) < 12 ) THEN $Hour=$Hour+12; ENDIF ENDIF ELSE $Hour = subStr( $CurrTime, 0, 2); $Minutes = subStr( $CurrTime, 3 , 2); IF( subStr( $CurrTime, 6 , 2) == "PM" ) THEN IF ( ToNum ($Hour) < 12 ) THEN $Hour=$Hour+12; ENDIF ENDIF ENDIF ### End ### ### Get Hour and Minutes from the upcoming event ### $Hour_event = SubStr ( GetStoredValue( $storage_name . "time_" . $race_number ) , 0 ,2 ); $Minutes_event = SubStr ( GetStoredValue( $storage_name . "time_" . $race_number ) , 3 ,2 ); $Timezone_event = SubStr ( GetStoredValue( $storage_name . "time_".$race_number ) , 6 ,4 ); ### End ### IF ( $Hour < $Hour_event ) THEN Set_server_settings ( $KeyFlags,"check_today_" . $race_number ); $event_found="yes"; IF ( GetStoredValue( "SCHDL_EVENT_END") == "After 3 hours" ) THEN $Hour_end_event = $Hour_event + 3; ENDIF IF ( GetStoredValue( "SCHDL_EVENT_END") == "After 2 hours" ) THEN $Hour_end_event = $Hour_event + 2; ENDIF IF ( GetStoredValue( "SCHDL_EVENT_END") == "After 2 hours" || GetStoredValue( "SCHDL_EVENT_END") == "After 3 hours" ) THEN IF ( $Hour_end_event > 24 ) THEN $Hour_end_event = $Hour_end_event -24; ELSE IF ( $Hour_end_event == 24 ) THEN $Hour_end_event = 0; ENDIF ENDIF ### Syntax: ss mm hh dayofweek dd MM YYYY ### RemoveScheduleAction( "check_track" ); RemoveScheduleAction( "check_schedule" ); RegisterScheduleAction( "end_of_event","* " . $Minutes_event . " " . $Hour_end_event . " * * * *" , end_of_event ); GlobalMsg ( "^7INFO: Announcement about and actual checking of schedule..." ); GlobalMsg ( "^7INFO: ... is postponed until " . $Hour_end_event . ":" . $Minutes_event . " " . $Timezone_event ); ENDIF BREAK; ELSE IF ( $Hour == $Hour_event && $Minutes <= $Minutes_event ) THEN Set_server_settings ( $KeyFlags,"check_today_" . $race_number ); $event_found="yes"; IF ( GetStoredValue( "SCHDL_EVENT_END") == "After 3 hours" ) THEN $Hour_end_event = $Hour_event + 3; ENDIF IF ( GetStoredValue( "SCHDL_EVENT_END") == "After 2 hours" ) THEN $Hour_end_event = $Hour_event + 2; ENDIF IF ( GetStoredValue( "SCHDL_EVENT_END") == "After 2 hours" || GetStoredValue( "SCHDL_EVENT_END") == "After 3 hours" ) THEN IF ( $Hour_end_event > 24 ) THEN $Hour_end_event = $Hour_end_event -24; ELSE IF ( $Hour_end_event == 24 ) THEN $Hour_end_event = 0; ENDIF ENDIF ### Syntax: ss mm hh dayofweek dd MM YYYY ### RemoveScheduleAction( "check_track" ); RemoveScheduleAction( "check_schedule" ); RegisterScheduleAction( "end_of_event","* " . $Minutes_event . " " . $Hour_end_event . " * * * *" , end_of_event ); GlobalMsg ( "^7INFO: Announcement about and actual checking of schedule..." ); GlobalMsg ( "^7INFO: ... is postponed until " . $Hour_end_event . ":" . $Minutes_event . " " . $Timezone_event ); ENDIF BREAK; ENDIF ENDIF ELSE IF ( GetStoredValue( "SCHDL_CHANGE") == "1 hour before event" ) THEN ### Get current time and extract current Hour and Minutes from it (converting Hour to 24-hour format if needed) ### $CurrTime = getLapperVar( "ShortTime" ); IF( subStr( $CurrTime, 1, 1) == ":" ) THEN $Hour = subStr( $CurrTime, 0, 1); $Minutes = subStr( $CurrTime, 2 , 2); IF( subStr( $CurrTime, 5 , 2) == "PM" ) THEN IF ( ToNum ($Hour) < 12 ) THEN $Hour=$Hour+12; ENDIF ENDIF ELSE $Hour = subStr( $CurrTime, 0, 2); $Minutes = subStr( $CurrTime, 3 , 2); IF( subStr( $CurrTime, 6 , 2) == "PM" ) THEN IF ( ToNum ($Hour) < 12 ) THEN $Hour=$Hour+12; ENDIF ENDIF ENDIF ### End ### ### Get Hour and Minutes from the upcoming event ### $Hour_event = SubStr ( GetStoredValue( $storage_name . "time_" . $race_number ) , 0 ,2 ); $Minutes_event = SubStr ( GetStoredValue( $storage_name . "time_" . $race_number ) , 3 ,2 ); $Timezone_event = SubStr ( GetStoredValue( $storage_name . "time_".$race_number ) , 6 ,4 ); ### End ### IF ( $Hour == $Hour_event && $Minutes <= $Minutes_event ) THEN Set_server_settings ( $KeyFlags,"check_1hour_" . $race_number ); $event_found="yes"; IF ( GetStoredValue( "SCHDL_EVENT_END") == "After 3 hours" ) THEN $Hour_end_event = $Hour_event + 3; ENDIF IF ( GetStoredValue( "SCHDL_EVENT_END") == "After 2 hours" ) THEN $Hour_end_event = $Hour_event + 2; ENDIF IF ( GetStoredValue( "SCHDL_EVENT_END") == "After 2 hours" || GetStoredValue( "SCHDL_EVENT_END") == "After 3 hours" ) THEN IF ( $Hour_end_event > 24 ) THEN $Hour_end_event = $Hour_end_event -24; ELSE IF ( $Hour_end_event == 24 ) THEN $Hour_end_event = 0; ENDIF ENDIF ### Syntax: ss mm hh dayofweek dd MM YYYY ### RemoveScheduleAction( "check_track" ); RemoveScheduleAction( "check_schedule" ); RegisterScheduleAction( "end_of_event","* " . $Minutes_event . " " . $Hour_end_event . " * * * *" , end_of_event ); GlobalMsg ( "^7INFO: Announcement about and actual checking of schedule..." ); GlobalMsg ( "^7INFO: ... is postponed until " . $Hour_end_event . ":" . $Minutes_event . " " . $Timezone_event ); ENDIF BREAK; ELSE IF ( $Hour+1 == $Hour_event && $Minutes <= $Minutes_event ) THEN Set_server_settings ( $KeyFlags,"check_1hour_" . $race_number ); $event_found="yes"; IF ( GetStoredValue( "SCHDL_EVENT_END") == "After 3 hours" ) THEN $Hour_end_event = $Hour_event + 3; ENDIF IF ( GetStoredValue( "SCHDL_EVENT_END") == "After 2 hours" ) THEN $Hour_end_event = $Hour_event + 2; ENDIF IF ( GetStoredValue( "SCHDL_EVENT_END") == "After 2 hours" || GetStoredValue( "SCHDL_EVENT_END") == "After 3 hours" ) THEN IF ( $Hour_end_event > 24 ) THEN $Hour_end_event = $Hour_end_event -24; ELSE IF ( $Hour_end_event == 24 ) THEN $Hour_end_event = 0; ENDIF ENDIF ### Syntax: ss mm hh dayofweek dd MM YYYY ### RemoveScheduleAction( "check_track" ); RemoveScheduleAction( "check_schedule" ); RegisterScheduleAction( "end_of_event","* " . $Minutes_event . " " . $Hour_end_event . " * * * *" , end_of_event ); GlobalMsg ( "^7INFO: Announcement about and actual checking of schedule..." ); GlobalMsg ( "^7INFO: ... is postponed until " . $Hour_end_event . ":" . $Minutes_event . " " . $Timezone_event ); ENDIF BREAK; ENDIF ENDIF ENDIF ENDIF ENDIF IF ($day_schdl > $day) THEN IF ( GetStoredValue( "SCHDL_CHANGE") == "Day of event" ) THEN Set_server_settings ( $KeyFlags,"check_0hour_" . $race_number ); $event_found="yes"; BREAK; ENDIF ENDIF ENDIF IF ($month_schdl > $month) THEN IF ( GetStoredValue( "SCHDL_CHANGE") == "Day of event" ) THEN Set_server_settings ( $KeyFlags,"check_0hour_" . $race_number ); $event_found="yes"; BREAK; ENDIF ENDIF ENDIF IF ($year_schdl > $year) THEN IF ( GetStoredValue( "SCHDL_CHANGE" ) == "Day of event" ) THEN Set_server_settings ( $KeyFlags,"check_0hour_" . $race_number ); $event_found="yes"; BREAK; ENDIF ENDIF ENDFOR ### When no event is found, clear the track for driving ### IF ( $event_found == "no" ) THEN GlobalMsg ( "^7Daily/hourly check - No scheduled race found" ); $server_name_schedule = StripLFSColor( getLapperVar( "HostName" ) ); $storage_name = "SCHEDULE_".$server_name_schedule."_"; cmdLFS("/pass " . GetStoredValue( $storage_name . "DEF_PWD" ) ); GlobalMsg ( "^7Daily/hourly check - Default server password has been set" ); $join_track_allowed="true"; ### Clear GlobalVars used for data storage ### $date_storage=""; $pwd_storage=""; ### End ### ENDIF ### End ### EndSub Sub end_of_event() RemoveScheduleAction( "end_of_event" ); $console_text="End of event "; writeline ( "----------".$console_text."start-------------" ); IF ( GetStoredValue( "SCHDL_STD_RACE" ) == "Yes" ) THEN IF ( getLapperVar( "ShortTrackName" ) != GetStoredValue( "SCHDL_STD_TRACK" ) ) THEN IF ( GetStoredValue( "SCHDL_STD_TRACK" ) != "" ) THEN $join_track_allowed = "false"; cmdLFS("/end"); writeline( $console_text."Race ended, track change needed" ); ### Set a 8 second DelayedCommand to change track ### ### Ending a race takes 3 seconds, then wait an extra 5 seconds before changing track ### DelayedCommand( 8, change_track_end_event ); openGlobalButton( "track_change_end_event",55,87,90,10,5,8,16,"^7Time left before track is changed: %cpt%", ); ### End ### ENDIF ENDIF IF ( getLapperVar( "allowedcars" ) != GetStoredValue( "SCHDL_STD_CARS" ) ) THEN IF ( GetStoredValue( "SCHDL_STD_CARS" ) != "" ) THEN cmdLFS("/cars " . GetStoredValue( "SCHDL_STD_CARS" ) ); writeline( $console_text."Car(s) changed" ); ENDIF ENDIF IF ( getLapperVar( "racelaps" ) != GetStoredValue( "SCHDL_STD_LAPS" ) ) THEN IF ( GetStoredValue( "SCHDL_STD_LAPS" ) != "" ) THEN cmdLFS("/laps " . GetStoredValue( "SCHDL_STD_LAPS" ) ); writeline( $console_text."Laps changed" ); ENDIF ENDIF cmdLFS("/pass " . GetStoredValue( "SCHDL_STD_PASSWORD" ) ); writeline( $console_text."Password changed" ); ENDIF Schedule_trackcheck (); ### Get StoredValue 'SCHDL_CHECK_RSA' from the database and split it into an array using the spaces as splitting character ### ### Get minute from arrayvalue 1 and reduce it by 1 minute ### ### In case $track_check_minute goes below zero, add 60 to its value ### ### Compile the new string for creating a Registered Scheduled Action ### $schedule_splitted = SplitToArray( GetStoredValue( "SCHDL_CHECK_RSA" )," " ); $track_check_minute = $schedule_splitted[1]-1; $track_check_hour = $schedule_splitted[2]; IF ( $track_check_minute < 0 ) THEN $track_check_minute = $track_check_minute + 60; IF ( $track_check_hour != "*" ) THEN $track_check_hour = $schedule_splitted[2]-1; IF ( $track_check_hour < 0 ) THEN $track_check_hour = $track_check_hour + 24; ENDIF ENDIF ENDIF $track_check_schedule = $schedule_splitted[0]." ".$track_check_minute." ".$track_check_hour." ".$schedule_splitted[3]." ".$schedule_splitted[4]." ".$schedule_splitted[5]." ".$schedule_splitted[6]; ### End ### ### Register two scheduled actions for both Track_check (announcement that check will happen in one minute and Schedule_trackcheck (actual check and changes if needed) ### ### Syntax: ss mm hh dayofweek dd MM YYYY ### RegisterScheduleAction( "check_track","" . $track_check_schedule, Track_check ); RegisterScheduleAction( "check_schedule","" . GetStoredValue( "SCHDL_CHECK_RSA" ), Schedule_trackcheck ); ### End ### writeline ( "----------".$console_text."finish------------" ); writeline ( "" ); writeline ( "" ); GlobalMsg ( "^7INFO: Announcement about and actual checking of schedule has resumed as scheduled" ); $join_track_allowed = "true"; EndSub Sub change_track_end_event() cmdLFS("/track " . GetStoredValue( "SCHDL_STD_TRACK" ) ); writeline( $console_text."Track changed" ); Endsub Sub Track_check() ### Announce that server settings will be checked in 1 minute ### cmdLFS( "/msg ^1In 1 minute the selected Track/car(s) will be ...^8" ); cmdLFS( "/msg ^1... checked and changed if needed^8" ); ### End ### EndSub Sub OnNewPlayerJoin_Schedule() ### If joining track is disallowed, notify the player about it, when he tries to join the track ### IF ($join_track_allowed == "false") THEN cmdLFS("/spec " . GetCurrentPlayerVar("UserName") ); Privmsg ( "^7Lapper is currently busy setting track/cars/password" ); ENDIF ### End ### ### Goto Sub Update_password ### IF ($join_track_allowed == "true") THEN Update_password ( $KeyFlags ); ENDIF ### End ### EndSub Sub Update_password ( $KeyFlags ) ### Set server_name and storage_name ### IF ($server_name_schedule == "") THEN $server_name_schedule = StripLFSColor( getLapperVar( "HostName" ) ); ENDIF ### End ### ### If $date_storage is empty, give it a value ### IF ( $date_storage == "" ) THEN $date_storage="xx-xx-xxxx"; ENDIF ### End ### ### If $pwd_storage is empty, give it a value ### IF ( $pwd_storage == "" ) THEN $pwd_storage="-"; ENDIF ### End ### ### Send data through HTTP function ### #http("http://sjoerd.rosdorff.dyndns.org/testlfs/test_pwd_lfs.php?servername=".$server_name_schedule."&date=".$date_storage."&password=".$pwd_storage); http("http://absolute-beginners.nl/e107_files/lapper/set_display_lfs_pwds.php?servername=".$server_name_schedule."&date=".$date_storage."&password=".$pwd_storage); ### End ### EndSub