Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   Global Message System (https://forums.graalonline.com/forums/showthread.php?t=78893)

xXziroXx 03-01-2008 06:48 AM

Global Message System
 
This is a newer, complete remake, of the Global Message/Event System (please don't post in that thread anymore, in fact, if a moderator feels like it - go ahead and delete it).

Simply put, it's an easy-to-install system that allowed you to send messages on RC too other servers that use the system. The more servers that start using it, the better. None of the "former" versions of the old system works anymore.



Current version: 1
------------------------
Functions:
* Ability to send global messages to all servers that use this system.
* Ability to send private messages to all servers that use this system.
* Ability to turn on/off the display of the messages.
* Ability to check the current players/playercount on all servers that use this system.
------------------------
Commands:
/npcglobalmsg "text in quotes"
/npcsendmsg servername "text in quotes"
/npcplayers servername

Step-by-step Installation Guide

1) Create a new database NPC, and name it "GlobalSys", then copy and paste this code.

PHP Code:

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

function 
doConnect()
{
  
enum {
    
//-- EDIT THESE --\\
    
SERVER "SERVER NAME HERE",
    
ACCESS "account1,account2,account3,etc",
    
ENABLEMESSAGES true,

    
//-- DO NOT EDIT --\\
    
VERSION 1,
    
CHANNEL "#GlobalSys",
    
COMMANDS "globalmsg,sendmsg,players",
    
CHECKCOMMANDS "!globalmessagerequest,!servermessagerequest,!players"
  
};
  
sendtext("irc""logout""");
  
sendtext("irc""login"name);
  
sendtext("irc""join"CHANNEL);
  
sendtext("irc""privmsg", {CHANNEL, { "!register"SERVERVERSIONENABLEMESSAGES }});
}

function 
onReceiveText(texttypetextoptionstextlines)
{
  if (
texttype == "irc") {
    switch (
textoptions) {
      case 
"privmsg":
        switch (
textlines[2][0]) {
          case 
"!globalmsg":
            if (
textlines[2][1] != SERVER && ENABLEMESSAGES == true) echo(textlines[2][2]);
          break;
            
          case 
"!servermsg":
            if (
textlines[2][1] != SERVER && textlines[2][2] == SERVER && ENABLEMESSAGES == true) echo(textlines[2][3]);
          break;
          
          case 
"!getplayers":
            if (
textlines[2][1] == SERVER) {
              for (
iallplayers) {
                if (
i.level != NULLtemp.players.add(i.account);
                else 
temp.players.add(i.account SPC "(RC)");
              }
              
sendtext("irc""privmsg", {CHANNEL, {"!updateplayers"temp.players}});
            }
          break;
        }
      break;
      
      case 
"notice":
        if (
textlines[2][1] == SERVER) echo(textlines[2][2]);
      break;
    }
  }
}

public function 
hasAccess(acc) return player.account in ACCESS.tokenize();

public function 
doCommand(commandparam)
{
  if (
command in COMMANDS.tokenize()) (@command)(param[0], param[1]);
}

function 
globalmsg(text)
{
  if (
text != NULLsendtext("irc""privmsg", {CHANNEL, {CHECKCOMMANDS.tokenize()[0], player.accounttext}});
}

function 
sendmsg(svrtext)
{
  if (
text != NULLsendtext("irc""privmsg", {CHANNEL, {CHECKCOMMANDS.tokenize()[1], player.accounttextsvr}});
}

function 
players(svr)
{
  if (
svr != NULLsendtext("irc""privmsg", {CHANNEL, {CHECKCOMMANDS.tokenize()[2], svr}});


Edit the options SERVER, ACCESS and ENABLEMESSAGES to suit your needs. Please, do not alter the other options - doing so might result in a permanent ban from the system.

2) Add the following code inside an onRCChat() function in your Control-NPC.

PHP Code:

  // -- Events Bot Commands -- \\
  
temp.args params;
  
temp.args.delete(0);

  if ((
"GlobalSys").hasAccess(player.account)) ("GlobalSys").doCommand(params[0], temp.args); 


Of course, offensive chat or too much spam, will result in a timed ban from the system. If you violate it too much, you might even get a permanent ban.

Suggestions, feedback, comments - everything is appreciated. And please, use the forums built-in reputation system. If you think this is a horrible idea, give me bad rep, at least then I know its not liked.


Credits too napo who is hosting the HUB on AEON!

Twinny 03-01-2008 07:02 AM

Added on Ziro's nagging <3

xXziroXx 03-01-2008 07:44 AM

Thanks Twinny. :)

I'd also like to point out that you're helping this to grow by having the NPC on your server, you don't have to have global messages enabled. I plan on making a statistics website connected to the system sometime, and have servers transmit tons of data too it.

So please, upload it on your server. Dont like the spam? Just set ENABLEMESSAGES to false.

Thanks in advance!

cbk1994 03-01-2008 07:46 AM

Instead of using quotes, I would loop through your tokens -- really quite simple.

zokemon 03-01-2008 08:32 AM

Done.

xXziroXx 03-01-2008 12:22 PM

Quote:

Originally Posted by cbkbud (Post 1377245)
Instead of using quotes, I would loop through your tokens -- really quite simple.

Will not work with commands that needs two tokens or more, like:

/npcsendmsg servername "text in quotes"

So I wont do it, just for simplicity. If you're lazy enough to not use quotes, don't bother sending messages.

Dan 03-01-2008 03:14 PM

Nice Ziro :) I won't use it though..

cbk1994 03-01-2008 04:38 PM

Quote:

Originally Posted by xXziroXx (Post 1377250)
Will not work with commands that needs two tokens or more, like:

/npcsendmsg servername "text in quotes"

So I wont do it, just for simplicity. If you're lazy enough to not use quotes, don't bother sending messages.

It's all about convenience and polishing your scripts.

It certainly will work with commands with two or more tokens.

Switch 03-01-2008 06:27 PM

Added on Codein's Dev Circle :)
Developers Circle

Chompy 03-01-2008 06:56 PM

Well, the only thing that I would like to point out, is the use of tokenize without a paremeter, because atm you don't use a parameter, and tokenize without a parameter will tokenize spaces and commas, so if an account with a space in it is listed in the ACCESS enum, the account with a space in it won't function properly,..

PHP Code:

function onCreated() {
  
temp.test "Chompy,Te st,foo";
  
  echo(
test.tokenize());
  echo(
test.tokenize(","));


Output:

PHP Code:

Chompy,Te,st,foo   // size() = 4
Chompy,"Te st",foo // size() = 3 

So it should be ACCESS.tokenize(","); instead of ACCESS.tokenize(); in the hasAccess(acc) function

xXziroXx 03-01-2008 08:18 PM

Quote:

Originally Posted by Chompy (Post 1377296)
Well, the only thing that I would like to point out, is the use of tokenize without a paremeter, because atm you don't use a parameter, and tokenize without a parameter will tokenize spaces and commas, so if an account with a space in it is listed in the ACCESS enum, the account with a space in it won't function properly,..

PHP Code:

function onCreated() {
  
temp.test "Chompy,Te st,foo";
  
  echo(
test.tokenize());
  echo(
test.tokenize(","));


Output:

PHP Code:

Chompy,Te,st,foo   // size() = 4
Chompy,"Te st",foo // size() = 3 

So it should be ACCESS.tokenize(","); instead of ACCESS.tokenize(); in the hasAccess(acc) function

Give me a break, I spent all night converting a 2 year old code. :asleep:

Chompy 03-01-2008 08:40 PM

Quote:

Originally Posted by xXziroXx (Post 1377312)
Give me a break, I spent all night converting a 2 year old code. :asleep:

I forgot to add smilies to my post as I usually do >_<

anyways, <3 :p

xXziroXx 03-03-2008 09:09 PM

Current servers that's connected:


AEON
Dev Kozmule99
Dev Nocturax
Dev zokemon
Developers Circle
Litheria
Symphonia

xXziroXx 03-04-2008 09:10 PM

Minor update, only one new command added, but meh..



Current version: 1.1
------------------------
Functions:
* Ability to send global messages to all servers that use this system.
* Ability to send private messages to all servers that use this system.
* Ability to turn on/off the display of the messages.
* Ability to check the current players/playercount on all servers that use this system.
* Ability to check servers that uses this system. Displays servers playercount, and if they have global messages disabled or not.
------------------------
Commands:
/npcglobalmsg "text in quotes"
/npcsendmsg servername "text in quotes"
/npcplayers servername
-- New -- /npcservers

Step-by-step Installation Guide

1) If upgrading from an old version, replace your old code with this (might want to NOT replace the editable options). Otherwise, create a new database NPC, and name it "GlobalSys", then copy and paste this code.

PHP Code:

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

function 
doConnect()
{
  
enum {
    
//-- EDIT THESE --\\
    
SERVER "SERVER NAME HERE",
    
ACCESS "account1,account2,account3,etc",
    
ENABLEMESSAGES true,

    
//-- DO NOT EDIT --\\
    
VERSION 1.1,
    
CHANNEL "#GlobalSys",
    
COMMANDS "globalmsg,sendmsg,players,servers",
    
CHECKCOMMANDS "!globalmessagerequest,!servermessagerequest,!players,!checkservers"
  
};
  
sendtext("irc""logout""");
  
sendtext("irc""login"name);
  
sendtext("irc""join"CHANNEL);
  
sendtext("irc""privmsg", {CHANNEL, { "!register"SERVERVERSIONENABLEMESSAGES }});
}

function 
onReceiveText(texttypetextoptionstextlines)
{
  if (
texttype == "irc") {
    switch (
textoptions) {
      case 
"privmsg":
        switch (
textlines[2][0]) {
          case 
"!globalmsg":
            if (
textlines[2][1] != SERVER && ENABLEMESSAGES == true) echo(textlines[2][2]);
          break;
            
          case 
"!servermsg":
            if (
textlines[2][1] != SERVER && textlines[2][2] == SERVER && ENABLEMESSAGES == true) echo(textlines[2][3]);
          break;
          
          case 
"!getplayers":
            if (
textlines[2][1] == SERVER) {
              for (
iallplayers) {
                if (
i.level != NULLtemp.players.add(i.account);
                else 
temp.players.add(i.account SPC "(RC)");
              }
              
sendtext("irc""privmsg", {CHANNEL, {"!updateplayers"temp.players}});
            }
          break;
        }
      break;
      
      case 
"notice":
        if (
textlines[2][1] == SERVER) echo(textlines[2][2]);
      break;
    }
  }
}

public function 
hasAccess(acc) return player.account in ACCESS.tokenize(",");

public function 
doCommand(commandparam)
{
  if (
command in COMMANDS.tokenize(",")) (@command)(param[0], param[1]);
}

function 
globalmsg(text)
{
  if (
text != NULLsendtext("irc""privmsg", {CHANNEL, {CHECKCOMMANDS.tokenize(",")[0], player.accounttext}});
}

function 
sendmsg(svrtext)
{
  if (
text != NULLsendtext("irc""privmsg", {CHANNEL, {CHECKCOMMANDS.tokenize(",")[1], player.accounttextsvr}});
}

function 
players(svr)
{
  if (
svr != NULLsendtext("irc""privmsg", {CHANNEL, {CHECKCOMMANDS.tokenize(",")[2], svr}});
}

function 
servers()
{
  
sendtext("irc""privmsg", {CHANNEL, {CHECKCOMMANDS.tokenize(",")[3]}});


Edit the options SERVER, ACCESS and ENABLEMESSAGES to suit your needs. Please, do not alter the other options - doing so might result in a permanent ban from the system.

2) If you're doing a fresh install, add the following code inside an onRCChat() function in your Control-NPC.

PHP Code:

  // -- Events Bot Commands -- \\
  
temp.args params;
  
temp.args.delete(0);

  if ((
"GlobalSys").hasAccess(player.account)) ("GlobalSys").doCommand(params[0], temp.args); 


xXziroXx 03-04-2008 10:40 PM

Step-by-step Guide for customizing commands

1) In your GlobalSys database NPC, change for example the globalmsg command from:

PHP Code:

function globalmsg(text

Too:
PHP Code:

function msg(text

Also change the name of the command in the COMMANDS string, despite it being listed under "DO NOT CHANGE" (it won't be in the next version, heck, I'll even make sure no functions are called unless the name of the function is in that string!).

xXziroXx 03-06-2008 03:09 AM

Just added more commands and a check ensuring no commands that doesn't exist are called, nothing major. But still. Updated the HUB a little too, though.



Current version: 1.2
------------------------
Functions:
* Ability to send global messages to all servers that use this system.
* Ability to send private messages to all servers that use this system.
* Ability to turn on/off the display of the messages.
* Ability to check the current players/playercount on all servers that use this system.
* Ability to check servers that uses this system. Displays servers playercount, and if they have global messages disabled or not.
* Ability to find a player on any of the servers that use this system.
------------------------
Commands:
/npcglobalmsg "text in quotes"
/npcsendmsg servername "text in quotes"
/npcplayers servername
/npcservers
-- New -- /npcfindplayer playeraccount
-- New -- /npcgetlatesturl

Step-by-step Installation Guide

1) If upgrading from an old version, replace your old code with this (might want to NOT replace the editable options). Otherwise, create a new database NPC, and name it "GlobalSys", then copy and paste this code.

PHP Code:

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

function 
doConnect()
{
  
enum {
    
//-- EDIT THESE --\\
    
SERVER "SERVER NAME HERE",
    
ACCESS "account1,account2,account3,etc",
    
ENABLEMESSAGES true,

    
//-- CUSTOMIZEABLE --\\
    
COMMANDS "globalmsg,sendmsg,players,servers,findplayer,getlatesturl",

    
//-- DO NOT EDIT --\\
    
VERSION 1.2,
    
CHANNEL "#GlobalSys",
    
CHECKCOMMANDS "!globalmessagerequest,!servermessagerequest,!players,!checkservers,!findplayer,!getlatesturl"
  
};
  
sendtext("irc""logout""");
  
sendtext("irc""login"name);
  
sendtext("irc""join"CHANNEL);
  
sendtext("irc""privmsg", {CHANNEL, { "!register"SERVERVERSIONENABLEMESSAGES }});
}

function 
onReceiveText(texttypetextoptionstextlines)
{
  if (
texttype == "irc") {
    switch (
textoptions) {
      case 
"privmsg":
        switch (
textlines[2][0]) {
          case 
"!globalmsg":
            if (
textlines[2][1] != SERVER && ENABLEMESSAGES == true) echo(textlines[2][2]);
          break;
            
          case 
"!servermsg":
            if (
textlines[2][1] != SERVER && textlines[2][2] == SERVER && ENABLEMESSAGES == true) echo(textlines[2][3]);
          break;
          
          case 
"!getplayers":
            if (
textlines[2][1] == SERVER) {
              for (
iallplayers) {
                if (
i.level != NULLtemp.players.add(i.account);
                else 
temp.players.add(i.account SPC "(RC)");
              }
              
sendtext("irc""privmsg", {CHANNEL, {"!updateplayers"temp.players}});
            }
          break;
        }
      break;
      
      case 
"notice":
        if (
textlines[2][1] == SERVER) echo(textlines[2][2]);
      break;
    }
  }
}

public function 
hasAccess(acc) return player.account in ACCESS.tokenize(",");
public function 
validCommand(command) return command in COMMANDS.tokenize(",");

public function 
doCommand(commandparam)
{
  if (
command in COMMANDS.tokenize(",")) (@command)(param[0], param[1]);
}

function 
globalmsg(text)
{
  if (
text != NULLsendtext("irc""privmsg", {CHANNEL, {CHECKCOMMANDS.tokenize(",")[0], player.accounttext}});
}

function 
sendmsg(svrtext)
{
  if (
text != NULLsendtext("irc""privmsg", {CHANNEL, {CHECKCOMMANDS.tokenize(",")[1], player.accounttextsvr}});
}

function 
players(svr)
{
  if (
svr != NULLsendtext("irc""privmsg", {CHANNEL, {CHECKCOMMANDS.tokenize(",")[2], svr}});
}

function 
servers()
{
  
sendtext("irc""privmsg", {CHANNEL, {CHECKCOMMANDS.tokenize(",")[3]}});
}

function 
findplayer(pl)
{
  if (
pl != NULLsendtext("irc""privmsg", {CHANNEL, {CHECKCOMMANDS.tokenize(",")[4], pl}});
}

function 
getlatesturl()
{
  
sendtext("irc""privmsg", {CHANNEL, {CHECKCOMMANDS.tokenize(",")[5]}});


Edit the options SERVER, ACCESS and ENABLEMESSAGES to suit your needs. Please, do not alter the other options - doing so might result in a permanent ban from the system.

2) If you're doing a fresh install, add the following code inside an onRCChat() function in your Control-NPC. Otherwise replace your old with this.

PHP Code:

  // -- Events Bot Commands -- \\
  
temp.args params;
  
temp.args.delete(0);

  if ((
"GlobalSys").hasAccess(player.account) && ("GlobalSys").validCommand(params[0])) ("GlobalSys").doCommand(params[0], temp.args); 


Switch 03-06-2008 04:22 AM

Quote:

Script: Function globalmsg not found at line 71 in script of GlobalSys (in level onlinestartlocal.graal at pos (30.5, 30))
I get that error on the new version when I use /npcglobalmsg

xXziroXx 03-06-2008 04:30 AM

Quote:

Originally Posted by Switch (Post 1378166)
I get that error on the new version when I use /npcglobalmsg

Oops, that's what I get for pasting my own customized command in an update. Just change the function name msg to globalmsg.

Rapidwolve24 03-06-2008 05:24 AM

Damn Ziro, you're still working on this?

xXziroXx 03-06-2008 05:43 AM

Quote:

Originally Posted by Rapidwolve24 (Post 1378180)
Damn Ziro, you're still working on this?

More like remade it from scratch.

zokemon 03-07-2008 06:32 PM

I really wish these updates weren't mandatory. Can't you just add a flag that says if the update is required or not?

xXziroXx 03-07-2008 08:20 PM

Quote:

Originally Posted by zokemon (Post 1378332)
I really wish these updates weren't mandatory. Can't you just add a flag that says if the update is required or not?

Problem is, if a server isn't using the latest version, the other servers won't be able to get data from a server with the latest version (if a new command have been added).

However, there won't be so many frequent updates. The last two were basically things I forgot in the initial release.

cbk1994 03-07-2008 08:25 PM

Quote:

Originally Posted by xXziroXx (Post 1378357)
Problem is, if a server isn't using the latest version, the other servers won't be able to get data from a server with the latest version (if a new command have been added).

However, there won't be so many frequent updates. The last two were basically things I forgot in the initial release.

When they try to use a certian function, just be like "ERROR: Server blah does not have the current version and does not support ..."

xXziroXx 03-08-2008 06:14 AM

Quote:

Originally Posted by cbkbud (Post 1378363)
When they try to use a certian function, just be like "ERROR: Server blah does not have the current version and does not support ..."

I'd rather just release new versions less frequently. ^^

cbk1994 03-08-2008 06:16 AM

Quote:

Originally Posted by xXziroXx (Post 1378423)
I'd rather just release new versions less frequently. ^^

Or you could do that ...

Chompy 03-19-2008 01:05 AM

I'm just curious, because of about 10 minutes ago loads of UC and hosted servers were down/their npcserver was down/laggy

So, I said '/stats' in the rc window, waits 10 secs and it comes up, no npcserver is listed, then 20 secs later the npcserver pops up and the cpu list:

and at number 1:

1. 83.89092337 % GlobalSys (in level symp_onlinestartlocal.nw at pos (30.5, 30))


so.. what's up? :o

cbk1994 03-19-2008 01:24 AM

Quote:

Originally Posted by Chompy (Post 1380711)
I'm just curious, because of about 10 minutes ago loads of UC and hosted servers were down/their npcserver was down/laggy

So, I said '/stats' in the rc window, waits 10 secs and it comes up, no npcserver is listed, then 20 secs later the npcserver pops up and the cpu list:

and at number 1:

1. 83.89092337 o/o GlobalSys (in level symp_onlinestartlocal.nw at pos (30.5, 30))


so.. what's up? :o

KuJi all over again ...

Settle it the American way, sue 'em!

Angel_Light 04-12-2008 06:24 AM

I can't get this work at all. it won't respond with anything and everything apparently is being triggered properly from what I can tell.

xXziroXx 04-12-2008 04:06 PM

HUB is currently disabled due to massive abuse. A more secure version is being worked on.

Angel_Light 04-12-2008 05:57 PM

ok thanks


All times are GMT +2. The time now is 06:12 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.