Creation/Dev/Graal IRC: Difference between revisions

From Graal Bible
No edit summary
No edit summary
Line 1: Line 1:
'''http://www.antiunixmad.com/'''
Written by [[User:Skyld|Skyld]], 26/07/2005. Edits made by [[User:Stefan|Stefan]] since. Hooray for [[User:Stefan|Stefan]]!
= IRC Information =
== Introduction ==
Graal 4 comes with a built-in form of IRC to allow people to chat between servers in rooms. Like IRC. But not, if you get my point. Now, there are ways in which you can use this IRC system to your advantage. Perhaps you want to script some kind of client for your players to use, or perhaps you want to script some kind of bot. Either way, the communication is simple.


'''[[Viper]]'s [[Graal]] Issues.'''
=== Links===
* [http://forums.graalonline.com/forums/showthread.php?t=60809 Graal v4 IRC Problem Information Thread]
* [[Creation/Dev/Troubleshooting Graal v4 IRC|Troubleshooting Graal v4 IRC]]


Hello everyone, as of late, many people have been attacking me on the issues and matters, trying to lie about things, bend the truth, and downright spin to make me and others of my cause look bad, in this text document i will discuss and lay to rest the issues that matter.
== Logging In ==
To use the IRC, you just need to have basic knowledge of sendtext() and onReceiveText(). The fundamentals are that you have three parameters for each outgoing and incoming message. If you have used onReceiveText() before, you are likely to know
it has a structure like this:
<pre>function onReceiveText(texttype, textoptions, textlines)</pre>
The texttype will always equal "irc" if it is an IRC command. This helps to filter out unwanted commands from, say, the scripted RC. The textoptions will always equal the command that you've sent, and the textlines will equal any parameters necessary for that command.  


I have been involved [[Graal]] for over three years now, and i used to really like [[Graal]] and its admins alot, then slowly after about a year [[Graal]] and its admins went in a bad downward spiral, i still stuck with [[Graal]] in hopes [[Graal]] would pull itself out of this hole and [[Unixmad]] would go back to the right path, this however did not happen, instead [[Unixmad]] and even [[Stefan]] went fouler and lower than i could have imageined, First with fireing [[Pachuka]] and [[Fuitad]], two of the BEST [[Graal]] admins ever in my view for no other reason than disagreeing with his future plans, then if just fireing them was not bad enough, he threatend to sue them and kill they're families, this was so wrong and bad [[Fuitad]] even said he would punch [[Unixmad]] in the face for saying that if he met him in real life, but that was just the beginning of the downward spiral [[Unixmad]] foolishly invoked onto [[Graal]], he then blatantly STOLE a domain name [[Graal]].net from Owl Shimy which costed over 30$ US Dollars, and never gave it back to him and never paid him for the cost of the domain, he also threatend to sue Owl Shimy and kill his family although it was [[Unixmad]] which stole the domain from Owl Shimy, then around [[Graal]]1.3.1 he blocked off [[GServer]]s officially and threatend to sue anyone that ran the former [[GServer]]s, although they were released as "Freeware" and actually used to encourage people to use the [[GServer]]s, this was a blatant attempt to monopolise , threaten, and intemidate that players that actually helped [[Graal]] and supported him, he then made claims he copyrighted "[[Graal]]" and would contact so called "Lawres" about anyone that used the name "[[Graal]]" or had "[[Graal]] Files" on there websites, although [[Graal]] was distributed as "Freeware" or "Shareware" and had no official software copyrights related to it, and that the name "[[Graal]]" was actually the name of a holy sacred golden cup used in some religion, and in that he has commited blasphemy against whatever religion has the so called "Holy [[Graal]]", then later on [[Unixmad]] fired SuperNick, because of his country and his origion and called him an American Asian slut, this was the first sign of racism on the part of [[Unixmad]], towards [[Graal]]1.4.1 [[Unixmad]] was secretly unwrapping his sadistic plans, he then started claiming credit and claiming to own the copyrights to [[Graal]], although [[Unixmad]] has done nothing but host some stupid weak as servers, and yet [[Stefan]] Knorr has done all the real work for [[Graal]], and was the one to make ZeldaOnline , [[Graal]]Online in the first place and has written every bit of codeing for the [[Graal]] Client , [[GServer]], RC, ect, yet [[Unixmad]] the worthless pile of trash that he is steals all credit for [[Graal]], then in February 2001, [[Unixmad]] and Antago release [[Graal]]2001 and the start of the "Pay to Play" system, now i have no problem with the fact that it is pay to play, the issue is when you PAY for something you actually expect to get the worth while of your money in this product, but instead they got a shittily made level generated land that was 99% empty, the NPCs were and are laggy as hell, and there were no quests, and there is only two shitty things today for hearts that suck so much i refuse to even call them quests, and to add to that about 40% of everyone that paid and gave [[Unixmad]] there credit card number NEVER got the accounts they paid 27$ or more for, and those that did clearly got chumped out by a cheap peice of crap that aint worth paying for, it sucked so badly that most people played on [[Graal]] Classic still, even those that foolishly paid for pay to play accounts, and in an attempt to "FORCE" people to pay for a shitty product they do not want against they're will [[Unixmad]] hired "Tyhm" to deface and ruin [[Graal]]Classic in an attempt to make it buggier and less fun than even [[Graal]]2001, about this time i was disgusted with [[Unixmad]] and most of the other admins and decided to downright turn against [[Graal]] and for the most part stop playing the peice of crap in general. People starting getting angry, complaining, asking for help, and asking for refunds, of coarse [[Unixmad]] gave noone a cash refund, and simply deleted and banned "PAID ACCOUNTS" of those who complained, asked for help, or asked for a refund these are PAYING CUSTOMERS, they have the rights of basic service that they PAID for, [[Unixmad]] promises pay to play players a quality product and customer service, but instead gives them a grade F product and ripps off his customers and delete they're accounts that they PAID HIM money for, his excuse? Credit card fraud, when infact at least 90% of the people he bans for credit card fraud pay legitamately with there OWN credit cards or pay via paypal by check, and yet [[Unixmad]] has stolen and used others credit card numbers to buy things for himself on several occassions, he also claims he needs pay to play money to keep [[Graal]] alive and running, yet there has been evidence that he makes at least 90% profit out of the monies he gets, and that he uses illegal porn ad banners and illegal cookie style web tracking and giveing email adresses of the players and even phone numbers of every player to spam and telemarketting companies without there permission, he even keeps personal player info, includeing email, adress, and phone number on unsecure servers which have already been leaked out, such info about people should not be on a public webserver accessable to the internet in anyway, then after all that [[Unixmad]] starts banning african american people, asians, koreans, and or people with images of people of that race from the [[Graal]]2001 forums and [[Graal]] itself, yet again they are paying customers and this is another sickening act of racism on the part of [[Unixmad]] and [[Graal]]Online, and then even more disgusting is what [[Stefan]] posts on the [[Graal]]2001 forums, he makes several anti american, racist, pro terrorist, pro nazi, and pro taliban comments on that post and goes on and on several pages bashing americans, this post was offense, obcene, and disgusting to many people includeing myself . If all that does not make you sick to your stomache or dislike [[Unixmad]] yet, i am far from done, then [[Unixmad]] proceeds to illegally DDOS webservers of mafukie and make threats to him over the phone, and has phone assaulted me over 40 times a day between midnight and 5am, and has made threats to sue dozens of people, kill there families, and shut down innocent websites and servers, while hosting illegal stuff and doing illegal things himself with the use of his own wanadoo.fr servers, stuff which includes child porn, bestiality porn, DVD Piracy, DDOS Attacks, theft of copyrighted materials from gameing companies such as nintendo, Credit Card fraud, theft, spamming, phone harrassment, useage of illegal pirated corperate softwares, all this just to start the list of what [[Unixmad]]', [[Stefan]], and they're servers are doing 24/7 for nearly 4 years now , anyone that likes [[Unixmad]] or thinks he is a good person even after all this is clearly a fool, everything in this document is the truth and why i hate [[Unixmad]] so much, if you like [[Unixmad]] after all these sickening things he does, then you are no better than a KKK or Neo Nazi member and should go kill yourselfs, i do not tolerate facists, racists, or nazis, they are all bad people, and [[Unixmad]] is one of the worst of the worst, and no person with any morales could tolerate or support such a person like Stephane Portha or [[Stefan]] Knorr. The people that spin, lie and bend the truth in support of [[Unixmad]] will always exist, but i will always reveal the truth about [[Unixmad]], and EVERYTHING said in this document is true, despite what any assclowns try and say about this, and this supriseingly enough is only 1% of the bad things [[Unixmad]] has done, how some people even tolerate, none the less support such a bad person is beyond me... I fight against bad people like [[Unixmad]], why? Because unlike many others in this world i actually care about other people, and i will do everything in my power to stop [[Unixmad]] from hurting [[Graal]] or its innocent players, many say i want to destroy and kill [[Graal]], this is NOT true, i used to love [[Graal]], i only wish to stop [[Unixmad]]'s evil sadistic illegal actions and restore [[Graal]] to the great game it used to be when it was "for the players, by the players" , but if i have to destroy [[Graal]]Online in exchange to stop [[Unixmad]]'s tyranny, it will be regreteable, but sometimes some sacrifices have to be made for the greater good, lets just hope that [[Unixmad]] drops dead and that sacrifice never has to be made... I love [[Graal]] and lots of its players, and i wish to someday restore it to the grandness it once had, but bad people like [[Unixmad]] must be gotten rid of if that is to be achieved...
An important thing to note is that the IRC server will not throw any errors at you if you make a mistake with a command, so you should ensure throughly that your requests are correct.
 
You send requests like this:
<pre>sendtext("irc", "command", "params");</pre>
Like any other IRC server, you need to log in before you can use it.
This is quite simply done. From your NPC, use the following command:
 
<pre>sendtext("irc", "login", "nickname");</pre>
 
'''NOTE:''' The nickname behaviour is different on the serverside. If you are logging in from the serverside, your nickname MUST begin with Graal, EventsBot or IRCBot. If you do not provide a valid nickname, then a suitable name (like IRCBot_2) will be automatically assigned and your nickname ignored.  
Now, with any luck, you will have been logged in successfully!<br>
'''NOTE2:''' There is also the command requesttext(texttype,textoption), but it is not used for irc communication since most irc commands require additional data.
 
== Joining a Channel ==
Now, you could probably get away with not joining a channel if you felt it necessary, but that would make communicating with you hard. So, why not join a channel? Joining and leaving channels is much like, again, in normal IRC. You sendtext("irc", "join", "#channame") to join a channel, and you sendtext("irc", "part", "#channame") to leave one.
 
You can be in multiple channels, however, if you are writing a bot, you should probably make sure that you are always replying to the correct channel. I suppose the same applies to if you are writing a client - make sure you are sending to the right channel!
 
== Receiving Information ==
Information from the IRC server comes to you in the form of onReceiveText(),providing you have logged into the server first. So, you will want to make sure that your script is receiving the information, or you might as well talk to a nice stone. I am not sure that it will help you, however.
 
Now, earlier in the document, I said about the onReceiveText structure.
Just for reference, it looks like this:
<pre>function onReceiveText(texttype, textoptions, textlines)</pre>
To ensure that you are only receiving information from the IRC server, you should put an if check to check that the texttype is always "irc":
<pre>if (texttype == "irc")
{
// Let's do this if we get IRC data
}
  else
{
  echo("I am receiving non-IRC data!");
}</pre>
'''NOTE:''' Commands like "privmsg" will be broadcasted to the whole channel, and will be sent back to you in the process. "join" and "part" are also sent to you to confirm that you have joined a channel, but can also be used for kicking.
 
The textoptions will equal the command type, such as "join", "part" or whatever.
 
So, you will want next to check what kind of information is being sent to you:
<pre>if (textoptions == "join") echo("You joined the channel successfully!");
if (textoptions == "part") echo("You left successfully");
if (textoptions == "privmsg") echo("Message!");</pre>
"privmsg" differs here - it contains messages from anyone, not just yourself. I'll explain about "privmsg" in a second. To know who is joining or leaving your channel you need to handle the "addchanneluser" and "deletechanneluser" types.
 
You may also receive information of the "notice" or "topic" types. These aren't so important yet and will be explained later.
 
== Working With Messages Specifically ==
The type you will most likely be interested in receiving is the "privmsg" command. This is the most complicated, as if it isn't used correctly, you'll end up no further forward then you were at the beginning of this section.
* When you send a "privmsg", you send the destination and the message.
* When you receive a "privmsg", you receive the source, destination and message.
 
So, let's assume that you've joined the channel #test. If you want to send a message to #test, you would use the following command:
<pre>sendtext("irc", "privmsg", {"#test", "THIS IS MY MESSAGE"});</pre>
 
A sensible idea would be to create a function that makes that mildly less tedious, so let's use this for example:
<pre>function send(dest, msg)
{
  sendtext("irc", "privmsg", {dest, msg});
}</pre>
Now, you can just use send("#test", "lolmsg"); to send a message to a channel or user.
 
However! Like I said before with "privmsg", what you get back will not be the same!
 
Instead of receiving {"destination","message"}, you will get {"source","destination","message"}, where source is the nickname that you logged in with. This allows you to find out who sent a message in the case that you are writing a client script, or for using people's names as an identity, say, with a bot.
 
So, what about parsing an incoming privmsg?  
<pre>function onReceiveText(texttype, textoptions, textlines)
{
if (texttype == "irc")
{
  if (textoptions == "privmsg")
  {
    // Do some stuff here
  }
}
}</pre>
In the function, you can read who sent the message with textlines[0], where it was directed to with textlines[1] (say, #test) and the actual message with textlines[2].
 
== Logging Out ==
If you are writing a client, or a bot that might have a reason to log out of the IRC server, you send a "logout" command like this:
<pre>sendtext("irc", "logout", "");</pre>
'''NOTE:''' The third parameter is ignored in this case.
 
== Other IRC Commands ==
There are a couple of other IRC commands, such as ''TOPIC'' and ''NOTICE''.
 
=== topic (Channel Topic) ===
''TOPIC'' commands are used to set the topic of a channel. This might be useful for you if you are writing a client, and simply uses this format:
<pre>sendtext("irc", "topic", {"#channel", "Topic goes here"});</pre>
You should also receive any ''TOPIC'' commands in the same format.
 
=== notice (Notices) ===
''NOTICE'' is similar to ''PRIVMSG'', but is considered less important, and while ''PRIVMSG'' to a single player is automatically converted into a regular [[PM]], ''NOTICE'' is not, and can so be used for sending information back to the user. The events bot is using ''NOTICE'' commands for event management.
 
=== addchanneluser (Channel Join Notifications) ===
''ADDCHANNELUSER'' is received when a new user joins a channel. The received data contains the channel name, irc nick, [[Server|Graal server]] and account name of the new user.
 
=== deletechanneluser (Channel Part Notifications) ===
''DELETECHANNELUSER'' is received when a user leaves a channel. Only the channel name and the irc nick of the leaving user are received.
 
== Multiple bots on one machine ==
It is possible to have more than one irc bot per machine - on the client you need to use two different weapon scripts which both login to the irc, on serverside you must use two independent database npcs or weapon scripts which both login to the irc and possibly use different nicknames.
 
= Extra Information =
== Events Bots ==
For making it possible that events from your [[server]] are displayed on the global events list of [[Graal4]], the server needs to have an '''EventsBot'''. That is an irc bot with a name starting with EventsBot. That [[NPC|npc]] or weapon npc automatically gets information about when events should be started. It needs to login to the irc and then wait for instructions using '''onReceiveText'''. If there is no EventsBot for the server, then events will not work for it. The EventsBot also needs to send some information to the IRCBot about who is [[Events Team|Events Admin]] on the server, and which channel should be used for talking about the events. That must be done as answer to a "!eventsbotlogin" message from the IRC Bot:
 
<pre>
function onCreated() doConnect();
function onInitialized() doConnect();
function onServerListerConnect() doConnect();
 
function doConnect()
{
  sendtext("irc", "login", "EventsBot");
  sendtext("irc", "privmsg", {"IRCBot", "!resetevents"});
}
 
function onReceiveText(texttype,textoption,textlines)
{
  if (texttype == "irc" && textoption == "privmsg" &&
  textlines[0] == "IRCBot" && textlines[2] == "!eventsbotlogin")
  {
    sendtext("irc", "privmsg", {"IRCBot", {"!eventadmins", "AccountName", "AccountName2"}});
    sendtext("irc", "privmsg", {"IRCBot", {"!eventchannel", "#ChannelName"}});
  }
}
</pre>
 
The EventsBot will also need to start events on the server, and tell the IRCbot about the status of the events.
 
== Quick Reference ==
Here are some quick reference notes.
 
=== Outgoing data ===
Usage:
<pre>sendtext("irc", command, parameters)</pre>
Format:
* '''command:''' ''parameters'' - description
Outgoing data:
* '''login:''' ''name'' - Connects to the IRC using name as the connection's nickname
* '''logout:''' ''""'' - Disconnects from the IRC
* '''privmsg:''' ''{destination, message}'' - Sends a message to a channel or user
* '''notice:''' ''{destination, message}'' - Sends a "notice" message to a channel or user
* '''join:''' ''channelname'' - Join channelname
* '''part:''' ''channelname'' - Leave channelname
* '''topic:''' ''{channel, topic}'' - Set the topic for the channel
 
=== Incoming data ===
Usage:
<pre>function onReceiveText(texttype, textoptions, textlines)</pre>
Format:
* '''textoptions:''' ''textlines'' - description
Note:
''The texttype will always be "irc" when information is sent from the IRC server.''
Incoming data:
* '''privmsg:''' ''{source, destination, message}'' - Sends the ''source'' of a message, where the message was directed to (''destination'') and the message
* '''notice:''' ''{source, destination, message}'' - Sends the ''source'' of a notice, where the notice was directed to (''destination'') and the notice
* '''addchanneluser:''' ''{channel, name, (servername), (account)}'' - Mechanism used to alert IRC scripts when users have joined the current channel, and lists users in the channel upon join. Shows the ''channel'' that ''name'' joined.
* '''deletechanneluser:''' ''{channel, name}'' - Mechanism used to alert IRC scripts when users have left the current channel
* '''join:''' ''{channel}'' - Mechanism used to confirm that you have joined ''channel''
* '''part:''' ''{channel}'' - Mechanism used to confirm that you have left ''channel''
 
=== Nickname Rules ===
If you are connecting from the serverside, you must start your nickname with one of the following:
* IRCBot_
* EventsBot_
* Graal_
If an invalid nickname is provided from the serverside, you will automatically be assigned with an IRCBot_'''n''' nickname.
 
Nicknames should not contain spaces.
 
== IRCBots for Old Scripting ==
It is now possible for servers using the old scripting engine to do IRCBots using the commands sendtext, requesttext, and the "if (receivetext)" event. A script example for a simple EventsBot:
 
<pre>
if (created || initialized || serverlisterconnect) {
  doConnect();
}
 
function doConnect() {
  sendtext irc,logout,;
  sendtext irc,login,EventsBot_OldScript;
  setstring this.options,;
  addstring this.options,IRCBot;
  addstring this.options,!resetevents;
  sendtext irc,privmsg,#s(this.options);
  sendtext irc,join,#OldScriptTest;
}
 
if (receivetext) {
  sendtonc irc: #p(0) - #p(1) - #p(2) - #p(3) - #p(4) - #p(5) - #p(6) - #p(7);
  if (strequals(#p(0),irc) && strequals(#p(1),privmsg) &&
      strequals(#p(2),IRCBot)) {
    if (strequals(#p(4),!eventsbotlogin)) {
      setstring this.options,;
      addstring this.options,IRCBot;
        setstring this.options2,;
        addstring this.options2,!eventadmins;
        addstring this.options2,Stefan;
        addstring this.options2,Spark910;
      addstring this.options,#s(this.options2);
      sendtext irc,privmsg,#s(this.options);
 
      setstring this.options,;
      addstring this.options,IRCBot;
        setstring this.options2,;
        addstring this.options2,!eventchannel;
        addstring this.options2,#OldScriptTest;
      addstring this.options,#s(this.options2);
      sendtext irc,privmsg,#s(this.options);
    } else if (strequals(#p(4),!startevent)) {
    } else if (strequals(#p(4),!resetevent)) {
    }
  }
}
</pre>
 
You also need to add a few script lines to the Control-NPC because in old scripting only the Control-NPC gets an event if the serverlister (=irc server) is reconnecting:
 
<pre>
if (serverlisterconnect) {
  with (getnpc(EventsBot)) {
    // Forwarding the event to the Events Bot
    callnpc -1,serverlisterconnect;
  }
}
</pre>

Revision as of 03:49, 1 July 2007

Written by Skyld, 26/07/2005. Edits made by Stefan since. Hooray for Stefan!

IRC Information

Introduction

Graal 4 comes with a built-in form of IRC to allow people to chat between servers in rooms. Like IRC. But not, if you get my point. Now, there are ways in which you can use this IRC system to your advantage. Perhaps you want to script some kind of client for your players to use, or perhaps you want to script some kind of bot. Either way, the communication is simple.

Links

Logging In

To use the IRC, you just need to have basic knowledge of sendtext() and onReceiveText(). The fundamentals are that you have three parameters for each outgoing and incoming message. If you have used onReceiveText() before, you are likely to know it has a structure like this:

function onReceiveText(texttype, textoptions, textlines)

The texttype will always equal "irc" if it is an IRC command. This helps to filter out unwanted commands from, say, the scripted RC. The textoptions will always equal the command that you've sent, and the textlines will equal any parameters necessary for that command.

An important thing to note is that the IRC server will not throw any errors at you if you make a mistake with a command, so you should ensure throughly that your requests are correct.

You send requests like this:

sendtext("irc", "command", "params");

Like any other IRC server, you need to log in before you can use it. This is quite simply done. From your NPC, use the following command:

sendtext("irc", "login", "nickname");

NOTE: The nickname behaviour is different on the serverside. If you are logging in from the serverside, your nickname MUST begin with Graal, EventsBot or IRCBot. If you do not provide a valid nickname, then a suitable name (like IRCBot_2) will be automatically assigned and your nickname ignored. Now, with any luck, you will have been logged in successfully!
NOTE2: There is also the command requesttext(texttype,textoption), but it is not used for irc communication since most irc commands require additional data.

Joining a Channel

Now, you could probably get away with not joining a channel if you felt it necessary, but that would make communicating with you hard. So, why not join a channel? Joining and leaving channels is much like, again, in normal IRC. You sendtext("irc", "join", "#channame") to join a channel, and you sendtext("irc", "part", "#channame") to leave one.

You can be in multiple channels, however, if you are writing a bot, you should probably make sure that you are always replying to the correct channel. I suppose the same applies to if you are writing a client - make sure you are sending to the right channel!

Receiving Information

Information from the IRC server comes to you in the form of onReceiveText(),providing you have logged into the server first. So, you will want to make sure that your script is receiving the information, or you might as well talk to a nice stone. I am not sure that it will help you, however.

Now, earlier in the document, I said about the onReceiveText structure. Just for reference, it looks like this:

function onReceiveText(texttype, textoptions, textlines)

To ensure that you are only receiving information from the IRC server, you should put an if check to check that the texttype is always "irc":

if (texttype == "irc")
{
 // Let's do this if we get IRC data
} 
  else
{
  echo("I am receiving non-IRC data!");
}

NOTE: Commands like "privmsg" will be broadcasted to the whole channel, and will be sent back to you in the process. "join" and "part" are also sent to you to confirm that you have joined a channel, but can also be used for kicking.

The textoptions will equal the command type, such as "join", "part" or whatever.

So, you will want next to check what kind of information is being sent to you:

if (textoptions == "join") echo("You joined the channel successfully!");
if (textoptions == "part") echo("You left successfully");
if (textoptions == "privmsg") echo("Message!");

"privmsg" differs here - it contains messages from anyone, not just yourself. I'll explain about "privmsg" in a second. To know who is joining or leaving your channel you need to handle the "addchanneluser" and "deletechanneluser" types.

You may also receive information of the "notice" or "topic" types. These aren't so important yet and will be explained later.

Working With Messages Specifically

The type you will most likely be interested in receiving is the "privmsg" command. This is the most complicated, as if it isn't used correctly, you'll end up no further forward then you were at the beginning of this section.

  • When you send a "privmsg", you send the destination and the message.
  • When you receive a "privmsg", you receive the source, destination and message.

So, let's assume that you've joined the channel #test. If you want to send a message to #test, you would use the following command:

sendtext("irc", "privmsg", {"#test", "THIS IS MY MESSAGE"});

A sensible idea would be to create a function that makes that mildly less tedious, so let's use this for example:

function send(dest, msg)
{
  sendtext("irc", "privmsg", {dest, msg});
}

Now, you can just use send("#test", "lolmsg"); to send a message to a channel or user.

However! Like I said before with "privmsg", what you get back will not be the same!

Instead of receiving {"destination","message"}, you will get {"source","destination","message"}, where source is the nickname that you logged in with. This allows you to find out who sent a message in the case that you are writing a client script, or for using people's names as an identity, say, with a bot.

So, what about parsing an incoming privmsg?

function onReceiveText(texttype, textoptions, textlines)
{
 if (texttype == "irc")
 {
   if (textoptions == "privmsg")
   {
     // Do some stuff here
   }
 }
}

In the function, you can read who sent the message with textlines[0], where it was directed to with textlines[1] (say, #test) and the actual message with textlines[2].

Logging Out

If you are writing a client, or a bot that might have a reason to log out of the IRC server, you send a "logout" command like this:

sendtext("irc", "logout", "");

NOTE: The third parameter is ignored in this case.

Other IRC Commands

There are a couple of other IRC commands, such as TOPIC and NOTICE.

topic (Channel Topic)

TOPIC commands are used to set the topic of a channel. This might be useful for you if you are writing a client, and simply uses this format:

sendtext("irc", "topic", {"#channel", "Topic goes here"});

You should also receive any TOPIC commands in the same format.

notice (Notices)

NOTICE is similar to PRIVMSG, but is considered less important, and while PRIVMSG to a single player is automatically converted into a regular PM, NOTICE is not, and can so be used for sending information back to the user. The events bot is using NOTICE commands for event management.

addchanneluser (Channel Join Notifications)

ADDCHANNELUSER is received when a new user joins a channel. The received data contains the channel name, irc nick, Graal server and account name of the new user.

deletechanneluser (Channel Part Notifications)

DELETECHANNELUSER is received when a user leaves a channel. Only the channel name and the irc nick of the leaving user are received.

Multiple bots on one machine

It is possible to have more than one irc bot per machine - on the client you need to use two different weapon scripts which both login to the irc, on serverside you must use two independent database npcs or weapon scripts which both login to the irc and possibly use different nicknames.

Extra Information

Events Bots

For making it possible that events from your server are displayed on the global events list of Graal4, the server needs to have an EventsBot. That is an irc bot with a name starting with EventsBot. That npc or weapon npc automatically gets information about when events should be started. It needs to login to the irc and then wait for instructions using onReceiveText. If there is no EventsBot for the server, then events will not work for it. The EventsBot also needs to send some information to the IRCBot about who is Events Admin on the server, and which channel should be used for talking about the events. That must be done as answer to a "!eventsbotlogin" message from the IRC Bot:

function onCreated() doConnect();
function onInitialized() doConnect();
function onServerListerConnect() doConnect();

function doConnect()
{
  sendtext("irc", "login", "EventsBot");
  sendtext("irc", "privmsg", {"IRCBot", "!resetevents"});
}

function onReceiveText(texttype,textoption,textlines)
{
  if (texttype == "irc" && textoption == "privmsg" &&
  textlines[0] == "IRCBot" && textlines[2] == "!eventsbotlogin")
  {
    sendtext("irc", "privmsg", {"IRCBot", {"!eventadmins", "AccountName", "AccountName2"}});
    sendtext("irc", "privmsg", {"IRCBot", {"!eventchannel", "#ChannelName"}});
  }
}

The EventsBot will also need to start events on the server, and tell the IRCbot about the status of the events.

Quick Reference

Here are some quick reference notes.

Outgoing data

Usage:

sendtext("irc", command, parameters)

Format:

  • command: parameters - description

Outgoing data:

  • login: name - Connects to the IRC using name as the connection's nickname
  • logout: "" - Disconnects from the IRC
  • privmsg: {destination, message} - Sends a message to a channel or user
  • notice: {destination, message} - Sends a "notice" message to a channel or user
  • join: channelname - Join channelname
  • part: channelname - Leave channelname
  • topic: {channel, topic} - Set the topic for the channel

Incoming data

Usage:

function onReceiveText(texttype, textoptions, textlines)

Format:

  • textoptions: textlines - description

Note: The texttype will always be "irc" when information is sent from the IRC server. Incoming data:

  • privmsg: {source, destination, message} - Sends the source of a message, where the message was directed to (destination) and the message
  • notice: {source, destination, message} - Sends the source of a notice, where the notice was directed to (destination) and the notice
  • addchanneluser: {channel, name, (servername), (account)} - Mechanism used to alert IRC scripts when users have joined the current channel, and lists users in the channel upon join. Shows the channel that name joined.
  • deletechanneluser: {channel, name} - Mechanism used to alert IRC scripts when users have left the current channel
  • join: {channel} - Mechanism used to confirm that you have joined channel
  • part: {channel} - Mechanism used to confirm that you have left channel

Nickname Rules

If you are connecting from the serverside, you must start your nickname with one of the following:

  • IRCBot_
  • EventsBot_
  • Graal_

If an invalid nickname is provided from the serverside, you will automatically be assigned with an IRCBot_n nickname.

Nicknames should not contain spaces.

IRCBots for Old Scripting

It is now possible for servers using the old scripting engine to do IRCBots using the commands sendtext, requesttext, and the "if (receivetext)" event. A script example for a simple EventsBot:

if (created || initialized || serverlisterconnect) {
  doConnect();
}

function doConnect() {
  sendtext irc,logout,;
  sendtext irc,login,EventsBot_OldScript;
  setstring this.options,;
  addstring this.options,IRCBot;
  addstring this.options,!resetevents;
  sendtext irc,privmsg,#s(this.options);
  sendtext irc,join,#OldScriptTest;
}

if (receivetext) {
  sendtonc irc: #p(0) - #p(1) - #p(2) - #p(3) - #p(4) - #p(5) - #p(6) - #p(7);
  if (strequals(#p(0),irc) && strequals(#p(1),privmsg) &&
      strequals(#p(2),IRCBot)) {
    if (strequals(#p(4),!eventsbotlogin)) {
      setstring this.options,;
      addstring this.options,IRCBot;
        setstring this.options2,;
        addstring this.options2,!eventadmins;
        addstring this.options2,Stefan;
        addstring this.options2,Spark910;
      addstring this.options,#s(this.options2);
      sendtext irc,privmsg,#s(this.options);

      setstring this.options,;
      addstring this.options,IRCBot;
        setstring this.options2,;
        addstring this.options2,!eventchannel;
        addstring this.options2,#OldScriptTest;
      addstring this.options,#s(this.options2);
      sendtext irc,privmsg,#s(this.options);
    } else if (strequals(#p(4),!startevent)) {
    } else if (strequals(#p(4),!resetevent)) {
    }
  }
}

You also need to add a few script lines to the Control-NPC because in old scripting only the Control-NPC gets an event if the serverlister (=irc server) is reconnecting:

if (serverlisterconnect) {
  with (getnpc(EventsBot)) {
    // Forwarding the event to the Events Bot
    callnpc -1,serverlisterconnect;
  }
}