You say it makes you freeze, but making it work for more than 1 network would make it even slower. So is best to first find out why it freezes. Surely there's something out there like P&P
https://mircscripts.net/1Vxgh which can do a lot of what you want.
First, before you make any changes to your script, be sure to copy it somewhere as a backup.
I did see one thing which is dumb, and is probably one of the causes of your freezes, assuming they happen at 10 seconds intervals. In your ON START event is the command:
.timerupdate 0 10 .scon 1 /update_joins
This causes your "update_joins" alias to run at 10 seconds FOREVER until there's a disconnect event on that server causing the timer to stop, and it never restarts until you restart mirc. "update_joins" appears to add all nicks from all nicklists from all channels into the @join window, so your window will fill very quickly. If you are in channels where the nicklists have a combined 100 nicks, then this timer would add lines to @join at the rate of 600 per minute. Remove that timer command from the script, and instead replace it with something which adds 1 nicklist as you join 1 channel. In the script there is currently a line which says:
if ($nick == $me) { halt }
Replace that line with:
if ($nick == $me) { timer 1 1 fill_nicklist_into_joins $unsafe($chan) | return }
Then insert this next alias above the line ";fill the sidebar with online users"
; fill sidebar with online users after YOU join it
alias fill_nicklist_into_joins {
if ($network != %joins.network) return
var %y $nick($1,0)
while (%y) { aline -nl @joins $nick($1,%y) | dec %y }
}
I know this is still not efficient because it adds the same nick several times if they share several channels with you. I am just getting the most benefit quickly.
-
Now, let's see how large your joins hashtable and your nicks.txt file are. When you paste this command in the editbox, what is the result:
//echo -ag nicks.txt $lines(nicks.txt) joins $hget(joins,0).item
--
Next, let's benchmark how long it takes to handle 1 person joining 1 channel. On the line below "on ^*:join:#: {" insert the line:
var %time $ticks
Next, a few lines below "clonescanner" is a line that has "haltdef". Insert this next line as a new line above the "haltdef":
echo -s $scriptline debug: time to handle $nick join in $chan is: $calc($ticks - %time) ms
This will cause a message in status window each time someone joins. The message contains the line of the script, which helps you find it later when is time to delete it. If the debug message shows the number of milliseconds is too high, the most likely problem is reading from disk.
A few lines above "clonescanner" is a line which contains "$checknick($nick)". Let's see the time taken by that line by doing the following. Insert a line above and below that line, so that 1 line now looks like these 3 lines:
old:
aline -p @joins 03 $+ $timestamp * $1 $+ 's other nicknames:01 $checknick($1)
new:
var %diskread $ticks
aline -p @joins 03 $+ $timestamp * $1 $+ 's other nicknames:01 $checknick($1)
echo -s $scriptline debug: time to checknick $nick is: $calc($ticks - %diskread) ms
If you can identify other events that seem to cause the freeze, then you can add debug messages to show how long other portions of the code are taking.
--
I've not verified my next change, but it seems that alias "checknick" is very inefficient, because it performs duplicate disk reads in order to retrieve data that it already has. Reading from disk is slow, and writing to disk can be even slower. For example, the current "checknick" code begins by scanning nicks.txt for a string match. Then instead of the /return using that scanned string, the /return performs a 2nd scan. Later in "checknick", it scans the nicks.txt for a line containing a string, then it uses a write command which scans a 2nd time to find that same line. Then when it returns a string to the caller, it wastes time again by scanning the diskfile for the string it just wrote to disk. For the disk reads, I also added the 'nt' switches. Even when the disk file does not contain text to be evaluated as if it is code, those switches save a small amount of time by not hunting for it.
Save the next change below for last, after you have done the above, to see if they solve your freeze. I did not test this alias, but I believe it works. If it does not work correctly, you can remove this alias and the code will continue to use the old "checknick" alias.
Insert this next alias as a replacement for alias "checknick" by pasting this next alias *above* the existing checknick alias, which makes the existing code call my alias instead of the existing "checknick" alias.
; substitute for alias checknick - delete or rename this alias if it does not work correctly
alias checknick {
if ($1 isin $read(nicks.txt, nts, $address($1, 2))) { return $v2 }
if (($read(nicks.txt, ntw, $address($1, 2) $+ *)) && ($1 !isin $read(nicks.txt, nts, $address($1, 2)))) {
var %oldnicks $v2
write -l $readn nicks.txt $address($1, 2) %oldnicks $+ , $1
return %oldnicks $+ , $1
}
write nicks.txt $address($1, 2) $1
return $1
}