mIRC Homepage
Posted By: NXwolf help with using files - 21/11/10 02:59 AM
I'm trying to get IRC to open/create, read, write, and close documents for information. I have been able to get IRC to manually do this by me typing in the commands in the main window, however, I'm trying to create a script that will do all this for me. I'm new to creating a database, so I'm trying to create something very basic while I pick up on how to make a databse.

The basis for what I'm trying to do is create administration logs for a gaming server's admin channel. When a player joins the server, his username, IP, hostname, and other information is displayed in the admin channel. I want a script that will read the username given and open or create (if file doesn't already exsist) a file with the username as the file name. The script will then paste the guys information along with the date and time he joined the server and then proceed to close the file. This process is repeated for every user and if the user already exsist, the newest line will appear on top and just keep pushing the older ones down.

I know all the commands and statements for the most part to get the above to work, but as soon as I create and mrc file with the program, it fails to work, as if IRC can't use the open, write, and close commands. Any reason if won't work?

Thanks a lot for your help.
Posted By: argv0 Re: help with using files - 21/11/10 03:09 AM
First of all, IRC is a protocol, mIRC is the client. IRC doesn't touch your filesystem.

Secondly, are you asking for something specific? How much of the script have you completed? If you're having problem with a specific script, post it, so that we can tell you what you did wrong. You do know how to load remotes, right? If not, /help remote or /help aliases
Posted By: NXwolf Re: help with using files - 21/11/10 05:00 AM
I'm running MIRC and some of the commands in it's help file allow me to open/create, read, write, and close files.

Quote:
/fopen [-no] <name> <filename>

Opens the specified file and assigns a name to it for later reference. The open fails if the file does not exist. The -n switch creates the file if it doesn't already exist, fails if the file does exist. The -o switch creates a new file, overwrites if it exists.

Note: If this command fails, the script will continue to run. See $ferr and $feof below.


/fclose <name | wildcard>

Closes the file associated with this name. If you specify a wildcard, all matching names are closed.


/flist [name | wildcard]

Lists all open files, or those matching the specified name.


/fseek <name> <position>

Sets the read/write pointer to the specified position in the file. The following switches may also be used to move the file pointer:

-l <name> <line number>
-n <name>
-w <name> <wildcard>
-r <name> <regex>


/fwrite [-bn] <name> <text | &binvar>

Writes text or the specified binary variable to the file. The -b switch indicates that a &binvar is being specified. The -n switch appends a $crlf to the line being written.


If I type all these commands in the main IRC window myself, IRC will execute them, but when I have a script tell IRC to use the commands, it won't. My script should be working, but I can't figure out why IRC won't accept the commands from a file instead of myself.
Posted By: RusselB Re: help with using files - 21/11/10 07:54 AM
If the commands that you are referring to are the /fopen, /fclose, etc. and you have the file name and directory specified correctly, I suspect that the file is being accessed correctly, just a lot faster than you're used to. This will always be the case when comparing a scripted solution to a manual solution.

If the commands are actually in the file you are reading, then file has to be read in a manner so that mIRC recognizes the lines as commands.

I'm not entirely familiar with how the file handling commands work, so I'm not sure what command you need to use that is the equivalent of $read

Since you state you have a script that isn't working, I recommend that you post the script so that we can review it and try to figure out why it's not working.
Posted By: Riamus2 Re: help with using files - 21/11/10 02:20 PM
The file handling commands (/fopen, /fwrite, /fclose, etc) are probably not what you really need based on what you said. Those are best used for writing a lot of data. If all you're doing is adding a little information to a file, then you're better off with /write.

Whatever you do, you have to use an event to make them work. You cannot just put the commands by themselves into the remotes tab. For example, if you already get the information in your admin channel, then you can use the on text event.

Let's say that your data that is posted to your admin channel looks something like this:

Joined: Nick IP Date Time

An event for that might be:

Code:
on *:text:*:#adminchannel: {
  if ($nick == botnick || $nick == altbotnick) {
    write $3 $1-
  }
}


That would write the line of data to a file named the same as the IP ("word" 3 in the example data, so $3). It will write only if the nick who posted the text is the bot's nick or the alternate bot's nick. That prevents writing data that isn't meant to be written. There are other ways as well that will let you prevent accidentally writing what someone is just talking about in the admin channel instead of only what the bot is telling you.

That's really just a basic example. If you want something specific, you need to provide an actual example of the data being posted to your admin channel and exactly what filename you want it written to and what you want written to the file.

To read the information, you'd use $read. Again, you need to put that into an event. You can use something like:

Code:
on *:text:!read *:#adminchannel: {
  msg $chan $read($2,nt,1)
}


Then, anyone in the admin channel can type !read IP (IP being the actual IP or whatever you're using as the filename) and they'll get information from the file.

Of course, that only reads line 1. If you want it to read multiple lines, you have to loop it and you'll probably want to only read a small number of lines or else add flood protection to the script because otherwise you'll message out too many lines at once and get disconnected for flooding. You'll probably also want to message an error message if the filename doesn't exist.

Again, if you want a specific example, you need to provide specific information and details including what you want to input, what you expect the output to be, what you want the filename to be, and what you want in the file. And anything else that you want it to do.
Posted By: NXwolf Re: help with using files - 22/11/10 06:49 AM
Basically I'm trying to do the following. (personal info removed)

[01:01:46] <APBBR> [Hostname Checker]: Name: Username IP: ***.***.***.*** Host: c-***-***-***-***.hsd1.il.comcast.net 10/07/2010 at 01:01am

I want the script to basically read the username and IP from this line of text and if the file doesn't exsist, create a file using the username and IP given, so say it's me. A file NXwolf.txt would be created. Then the script would read in the IP the comes from the APBBR bot and scan the txt file for that IP. If the IP doesn't exsist in the file, it will create a new line at the top of the document as seen below.

IP: IP found last on Date at Time

If the IP does exsist, it will delete that line of text and readd the IP data to the top of the list. This is so we can tell when the last time that IP was found on the server.

Then I will be creating a read system that will search by username. If file found, will return the content's listed in the file (up to latest 10 IP's found).

I would also like the script to be able to create files and store them via the IP using the same method above, but based on IP's and store usernames in a file based on IP. I'm just not sure how to get an IRC script to recognize a "." that's not a command, but part of the text itself.

Hope that explains more of what I'm trying to do.
© mIRC Discussion Forums