Comments on "Script functions documentation"

Discussion in 'Server and Client Scripting' started by Mystra, Sep 8, 2010.

Thread Status:
Not open for further replies.
  1. TheUnknownOne

    TheUnknownOne Member

    Joined:
    Mar 28, 2011
    Messages:
    988
    Likes Received:
    3
    Suggestions:

    mixed sys.mysql_query(string query) - runs a mysql query
    mixed sys.sqlite_query(string query) - runs a sqlite query
    mixed? sys.postgresql_query(string query) - runs a postgresql query
    string sys.getDBType(void) - returns type of db (MySQL, SQLite, PostGreSQL)
    number sys.lastQueryLoad(void) - prints time to evaluate last query.

    parameter add to sys.changeAnnouncement:
    bool print - default is true. if true, prints 'Announcement Changed' on the server window.

    int sys.clientVersion(int id) - returns client version by id. returns 0 on failure(old client)
    int sys.serverVersion(void) - returns server version.

    Config-based functions:

    bool sys.getPublic(void) - returns true if public, false if private.
    int/string sys.getPort(void) - returns server port.
    string sys.getServerIP(void) - returns server ip. (not config based, though)
    int/string sys.getMaxPlayers(void) - returns max players.
    bool sys.getSafeScripts(void) - returns if safe scripts is enabled
     
    Last edited: Nov 16, 2011
  2. Mystra

    Mystra Active Member

    Joined:
    Jul 12, 2010
    Messages:
    1,389
    Likes Received:
    4
    SQL queries… no one will do it (well, I tried to make some API for a subset of that, but no one was interested and I hate SQL so I can't do it alone), and it's unsafe too. tl;dr It was scrapped. Also, queries should not be different between DBs. It would be better to make separate API to effectively store/retrieve data. I dunno… Berkeley DB?

    >int sys.clientVersion(int id) - returns client version by id. returns 0 on failure(old client)
    I'm actually against this. Why would you want that? There is already a warning when client is not the same as server.

    >int sys.serverVersion(void) - returns server version.
    Might be useful, I'll see what can be done here.

    >bool print - default is true. if true, prints 'Announcement Changed' on the server window.
    >Reading server configuration
    I'd like to hear some examples on why would this be useful.

    >int/string sys.getMaxPlayers(void) - returns max players.
    I thought scripts counted that, so server does not know. No?

    Also, I need to catch coyotte first before starting things %) EDIT: Ok, don't need anymore. Let's try something.
     
    Last edited: Nov 17, 2011
  3. TheUnknownOne

    TheUnknownOne Member

    Joined:
    Mar 28, 2011
    Messages:
    988
    Likes Received:
    3
     
  4. Mystra

    Mystra Active Member

    Joined:
    Jul 12, 2010
    Messages:
    1,389
    Likes Received:
    4
    >I'm trying to make a code that eval's all code inside [eval] tags in the announcement.
    The path to madness :) Don't eval dynamic content, or eval at all unless you sure what you are doing. Why would you need that? Maybe there is another way to do what you want. As is it is abusing one system to make something it is not supposed to.

    And you haven't written why you need server config values.

    EDIT: Oh and serverVersion() is done. It returns a string, since PO version is one.
     
  5. Lamperi

    Lamperi I see what you did there

    Joined:
    Apr 25, 2010
    Messages:
    2,647
    Likes Received:
    11
    Server doesn't know client version. If that will be added probably a script version will too.

    One of those is something you can implement yourself:
    Code (text):
    1.  
    2. function myChangeAnnouncement(text, b) {
    3.     sys.changeAnnouncement(text);
    4.     if (b === undefined || b) print("Announcement Changed");
    5. }
    6.  
     
  6. TheUnknownOne

    TheUnknownOne Member

    Joined:
    Mar 28, 2011
    Messages:
    988
    Likes Received:
    3
     
  7. Kalashnikov

    Kalashnikov Despite the code quality

    Joined:
    Apr 4, 2011
    Messages:
    434
    Likes Received:
    0
    Nothing prevents you from reading config directly fmor file with getFileContent('config').
     
  8. TheUnknownOne

    TheUnknownOne Member

    Joined:
    Mar 28, 2011
    Messages:
    988
    Likes Received:
    3
    IP isn't stored there. The regexps required can do weird things...

    And since you can't change data by writing to the config, changing the server description on a remote host without access is impossible.

    Note: Haven't tested changing data and printing something such as 'Announcement Changed'.
     
  9. Kalashnikov

    Kalashnikov Despite the code quality

    Joined:
    Apr 4, 2011
    Messages:
    434
    Likes Received:
    0
    I see no use of knowing server IP, but whatever, you can find it out by querying remote host with webCall. Also good servers have static IPs anyway.
     
  10. Mystra

    Mystra Active Member

    Joined:
    Jul 12, 2010
    Messages:
    1,389
    Likes Received:
    4
    >Prevents /public & /private commands from being spammed and has some small uses outside of it.
    These commands should be allowed to owners, if they spam them… well, you need better owners.

    >adv connect
    What do you mean?

    >bool sys.getSafeScripts(void) - Prevent the message from coming on the server window if not changed at all.
    What? That message need to be fixed, no reason for reading what its state is.

    You don't really need your own IP anyway. To call your own scripts you either call them directly or use localhost. You don't usually send it outside…
     
  11. TheUnknownOne

    TheUnknownOne Member

    Joined:
    Mar 28, 2011
    Messages:
    988
    Likes Received:
    3
     
  12. Lamperi

    Lamperi I see what you did there

    Joined:
    Apr 25, 2010
    Messages:
    2,647
    Likes Received:
    11
    Code (text):
    1.  
    2. function getIpAddress()
    3. if (sys.system("/sbin/ifconfig > /tmp/ifconfig")) {
    4.     var s=sys.getFileContent("/tmp/ifconfig");
    5.     var i=out.indexOf("inet addr:");
    6.     return s.substring(i+10, s.indexOf(" ",i+11));
    7. } else if (sys.system("ipconfig > ipconfig.txt"){
    8.     var s=sys.getFileContent("ipconfig.txt");
    9.     // parse s here from the Windows's ipconfig output
    10.     return parsed;
    11. }
    12.  
     
  13. Mystra

    Mystra Active Member

    Joined:
    Jul 12, 2010
    Messages:
    1,389
    Likes Received:
    4
    >I meant that if the server is already private or public, it notifies
    Well, this might be useful, I guess. Let's see… EDIT: Added sys.isServerPrivate(). Well, that's what variable inside is named so it's a reverse of that, but still allow the same thing :}

    >an easy way to find the Advanced Connect of a server
    Err… when you enter server it's IP is saved in login screen. Copy from that later if you really want it :S
     
    Last edited: Nov 17, 2011
  14. TheUnknownOne

    TheUnknownOne Member

    Joined:
    Mar 28, 2011
    Messages:
    988
    Likes Received:
    3
    Works too:

    PHP:
    1.  
    2. <?php
    3. // In an online file, of course.
    4. die($_SERVER['REMOTE_ADDR']);
    5. // Yush, I used die here to skip some advertisements from free hosts.
    6. ?>
    7.  
    then:
    Code (javascript):
    1.  
    2. sys.webCall("http://foo.bar/ip.php",
    3. function(resp)
    4. {
    5. ServerIP = resp;
    6. });
    7.  
    Works if sys.system is disabled(which it should...)
     
  15. Mystra

    Mystra Active Member

    Joined:
    Jul 12, 2010
    Messages:
    1,389
    Likes Received:
    4
    >die($_SERVER['REMOTE_ADDR']);

    Hardcore. And yes, I've read comment after that :}
     
  16. Kalashnikov

    Kalashnikov Despite the code quality

    Joined:
    Apr 4, 2011
    Messages:
    434
    Likes Received:
    0
  17. TheUnknownOne

    TheUnknownOne Member

    Joined:
    Mar 28, 2011
    Messages:
    988
    Likes Received:
    3
    Is it possible to have a sys.microtime() or something similar? Doing it with webcall won't work because ip lookup.
     
  18. Mystra

    Mystra Active Member

    Joined:
    Jul 12, 2010
    Messages:
    1,389
    Likes Received:
    4
    I can haz translation?
     
  19. TheUnknownOne

    TheUnknownOne Member

    Joined:
    Mar 28, 2011
    Messages:
    988
    Likes Received:
    3
    Coded? If so, then here:

    PHP:
    1.  
    2. <?php
    3. //inside file
    4.  
    5. if(isset($_GET['float']) AND $_GET['float'] != FALSE) {
    6. $result = TRUE;
    7. }
    8. else {
    9. $result = FALSE;
    10. }
    11. die(microtime($result));
    12. ?>
    13.  
    Code (javascript):
    1.  
    2. // Inside server script
    3. function microtime() {
    4. sys.webCall("http://xxx.xxx/m.php?float=true",function(resp) {
    5. return resp;
    6. });
    7. }
    8. var arr = ['1','2','3'];
    9. var time_1 = microtime();
    10. for(var h = 0; h < arr.length; h++)
    11. {
    12. sys.sendAll(arr[h]);
    13. }
    14. var time_2 = microtime();
    15. var result = (time_2-time_1); // or something...
    16. sys.sendAll("Value Printing of arr took: "+result);
    17.  
    http://php.net/manual/en/function.microtime.php
     
  20. Kalashnikov

    Kalashnikov Despite the code quality

    Joined:
    Apr 4, 2011
    Messages:
    434
    Likes Received:
    0
    This won't do the job since sending a request to remote host and geting answer will take far more time than sendAll or any other code (You need synchronous web call here btw).
    You can create two Date objects: One before your code and one after and calculate approximate difference down to milliseconds. Anything faster than a milisecond doesn't even matter.
    Code (javascript):
    1.  
    2. >>> t = (new Date()).valueOf(); setTimeout('console.log( (new Date()).valueOf() - t )', 3000)
    3. 3002
    4.  
     
    Last edited: Nov 19, 2011
  21. Mystra

    Mystra Active Member

    Joined:
    Jul 12, 2010
    Messages:
    1,389
    Likes Received:
    4
    <-- still has no idea what microtime is and why it is needed.
     
  22. TheUnknownOne

    TheUnknownOne Member

    Joined:
    Mar 28, 2011
    Messages:
    988
    Likes Received:
    3
    Optimizing code and loading time display.
     
  23. Mystra

    Mystra Active Member

    Joined:
    Jul 12, 2010
    Messages:
    1,389
    Likes Received:
    4
    Pointless… ms is enough.
     
  24. GaryTheGengar

    GaryTheGengar You Know My Steez

    Joined:
    Aug 16, 2010
    Messages:
    22
    Likes Received:
    0
    getBattleMode(tier) to get the find battle mode of a tier, so tournament battles can be forced to be doubles, triples, etc
     
  25. Mystra

    Mystra Active Member

    Joined:
    Jul 12, 2010
    Messages:
    1,389
    Likes Received:
    4
    >find battle
    >tournament

    Umm… hi?
     
  26. Lamperi

    Lamperi I see what you did there

    Joined:
    Apr 25, 2010
    Messages:
    2,647
    Likes Received:
    11
    He means what is the mode of the tier: single, doubles, triples. Which is only enforced in find battle battles.
     
  27. Kalashnikov

    Kalashnikov Despite the code quality

    Joined:
    Apr 4, 2011
    Messages:
    434
    Likes Received:
    0
    Can be stored in scripts, I doubt you change tiers that often. Even if so, you can parse tiers.xml or name your tiers following some pattern.
    However, something like tierInfo() might be usefull in general (But again, can be implemented with xml parsing).
     
  28. Mystra

    Mystra Active Member

    Joined:
    Jul 12, 2010
    Messages:
    1,389
    Likes Received:
    4
    Oh… I'll see later. I'm not quite familiar how tiers are done there (^ ^) There some suggestions before about tier functions. Maybe I'll need to find those too %)
     
  29. Garma

    Garma Member

    Joined:
    Nov 23, 2011
    Messages:
    80
    Likes Received:
    0
    Has anyone already suggested sys.banIp(ip)? I didn't read the whole thread :x

    As far as I know it's not possible to ban an IP in a simple way. I wrote a function which bans every alias (actually, that equals banning an IP) of a player, but there should be a simple function like sys.banIp(ip) or sys.banAlias(player_name), just because it's easier and needs less code.

    Oh, and sys.banned(player_name) would be nice, to check if someone is banned.
     
    Last edited: Dec 1, 2011
  30. Lamperi

    Lamperi I see what you did there

    Joined:
    Apr 25, 2010
    Messages:
    2,647
    Likes Received:
    11
    PO does not support banning by IP or alias explicitely. The ban always contains the information about both.

    sys.banAlias(name) is equal existing function to sys.ban(name).

    You can make your own function to ban IP:
    Code (text):
    1.  
    2. function banIP(ip) {
    3.     var aliases = sys.aliases(ip);
    4.     if (aliases.length > 0)
    5.          sys.ban(aliases[0]); // Ban by name, but will ban the IP too.
    6. }
    7.  
     
  31. Garma

    Garma Member

    Joined:
    Nov 23, 2011
    Messages:
    80
    Likes Received:
    0
    I already had that I banned someone, he changed his name and came online again 10s later. I think banning an IP would be useful. But thanks for the function, I'll test it.
     
  32. Lamperi

    Lamperi I see what you did there

    Joined:
    Apr 25, 2010
    Messages:
    2,647
    Likes Received:
    11
    He must have changed IP then. OR he had two accounts online, you need to kick all online aliases manually (or via scripts).
     
  33. Blastcore

    Blastcore Developer

    Joined:
    Jul 19, 2010
    Messages:
    763
    Likes Received:
    1
    For MySQL you could use WebCalls to some PHP file. Wonder if that would work and if it's 'secure'?

    Hm.

    Lol
     
  34. TheUnknownOne

    TheUnknownOne Member

    Joined:
    Mar 28, 2011
    Messages:
    988
    Likes Received:
    3
    It does, but it's insanely slow. And it's not secure if someone knows what the url is and knows what arguments should be used.
     
  35. TheUnknownOne

    TheUnknownOne Member

    Joined:
    Mar 28, 2011
    Messages:
    988
    Likes Received:
    3
    Is there a file that contains all moves for every single pokemon(no levels required)?

    And, can Themes/Classic/types get images like
    [​IMG]
    prefixed with something like 'plain_' ? (base64 is too much coding :/)
     
  36. Lamperi

    Lamperi I see what you did there

    Joined:
    Apr 25, 2010
    Messages:
    2,647
    Likes Received:
    11
    No, the moves are put into several categories: level up, special, egg moves, dw moves. That way teambuilder and server can handle the legality checks
     
  37. TheUnknownOne

    TheUnknownOne Member

    Joined:
    Mar 28, 2011
    Messages:
    988
    Likes Received:
    3
    More suggestions:
    beforeCPBan(sourcename,targenamet) - before Control Panel ban
    afterCPBan(sourcename,targetname) - After.
    beforeCPLaunch(source) - Before CP is opened
    afterCPLaunch(source) - After.

    beforeBattleChatMessage(source,message,battleid) - Before message in battle chat.
    afterBattleChatMessage(source,message,battleid) - After.

    sys.sendBattleAll(message,(optional battleid)) - Sends message in all battle chats or in 1.
    sys.sendBattleHtmlAll(message,(optional battleid)) - Sends a message with HTML.

    sys.sendBattleMessage(id, message, (optional battleid)) - Sends a message to player in all battle chats or only 1.
    sys.sendBattleHtmlMessage(id, message, (optional battleid)) - Sends with HTML.

    sys.battles((optional id)) - returns a hash with:
    battleid
    battler1
    battler2
    for all battles on the server. (in a style like bid:[battler1,battler2])
    if id not specified.
    otherwise returns an array of all battles player is in.

    sys.forceSpectator(id, battleid) - Forces someone to spectate a battle
    sys.isSpectator(id, battleid) - returns if id is spectating battleid
    sys.battler(id, battleid) - returns false if id is not battling in battleid. else returns the number of the battler(1 or 2)
    sys.kickSpectator(id, battleid) - Removes a spectator from a battle.
    sys.numBattles() - returns number of battles.
    sys.endBattle(battleid) - ends battle battleid

    sys.changeWelcomeMessage(message) - changes content of the blue Welcome Message: if enabled as compile time option.
    sys.compileOption(optionname) - returns if optionname is enabled (compile time option). optionnames should be in lowercase or have a specific id.
    (Might add some others later.)

    Is there also a function that can be stopped and is launched before a battle is spectated?
     
    Last edited: Dec 14, 2011
  38. Blastcore

    Blastcore Developer

    Joined:
    Jul 19, 2010
    Messages:
    763
    Likes Received:
    1
    Going to add the Possibly ones after discussing with the devs.
     
    Last edited: Dec 14, 2011
  39. TheUnknownOne

    TheUnknownOne Member

    Joined:
    Mar 28, 2011
    Messages:
    988
    Likes Received:
    3
    beforeCPBan is for creating objects correctly.

    example: ban by command and ban by right click create an object named bans[namehere]. If the ban is from the CP, this object is missing and some bad behavior can happen.

    beforeUnban might be useful too for deleting these (Although not required).

    sys.endBattle is to stop bad battles and the like.

    for sys.compileOption, there is a documentation here of names:
    http://wiki.pokemon-online.eu/view/Scripting_options
     
  40. Mystra

    Mystra Active Member

    Joined:
    Jul 12, 2010
    Messages:
    1,389
    Likes Received:
    4
    PlayerBan is enough for this, unless it's not called at all.

    Useless.

    Would be nice, although I'm not sure whether there is interface exposed for that currently. I'll check later.

    Use cases…?

    Currently it's not stored anywhere, it's just right in the code on loading. What that means? Well, no idea yet.

    Might be useful too. Should be pretty easy.

    Don't expect anything to be done before next release though. It might happen if someone other than me will do it though. I can provide some help if someone is willing.
     
Thread Status:
Not open for further replies.