Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Online Log Reader (https://forums.graalonline.com/forums/showthread.php?t=134264155)

Emera 08-09-2011 08:01 PM

Online Log Reader
 
2 Attachment(s)
I was looking at cbk's login message GUI, and saw that it read the contents of a text file and showed it in a GUI text box. I took this idea and decided to make an online log reader so you can check your logs online. It is just a simple script however and I have thought about adding some more features like editing the text file via a GUI and some other stuff, but I need to read up on editing text files first. Anyway, if you guys think I should go ahead and post it in the code gallery, I will, but I want to see if there is anything you guys think I can improve here. You guys are more than welcome to post edited versions, fixes, advice and whatever else :D Thanks!

cbk1994 08-09-2011 08:10 PM

The first thing you need to fix is the terribly inconsistent styling.

Also, you should just use PHP tags for code that's not too long to post.

PHP Code:

function onActionServerSidecmd )
{
  if ( 
cmd == "getLogtext" )
  {
   
temp.l.loadLines"logs/systemmass.txt" );
    
triggerclient"gui"name"returnLogtext"temp.);
    }
    }

//#CLIENTSIDE
function onCreated()
{
triggerserver"gui"name"getLogtext" );
}
function 
showMessagenews )
{
  new 
GuiWindowCtrl("LogReader_Window")
  {
    
profile GuiBlueWindowProfile;
    
clientrelative true;
    
clientextent "589,516";
    
isexternal false;

    
canclose true;
    
canmaximize false;
    
canmove true;
    
canresize false;
    
closequery false;
    
destroyonhide false;
    
text "Log Reader";
    
370;
    
72;

    new 
GuiScrollCtrl("LogReader_MultiLine_Scroll")
    {
      
profile GuiBlueScrollProfile;
      
height 504;
      
hscrollbar "dynamic";
      
vscrollbar "dynamic";
      
width 576;
      
6;
      
7;

      new 
GuiMLTextCtrl("LogReader_MultiLine")
      {
        
profile GuiBlueMLTextProfile;
        
height 17;
        
horizsizing "width";
        
plaintext "";
        
text news;
        
width 551;
      }
    }
  }
}
function 
onPlayerChats()
{
if (
player.chat == "/showlog")
{
if(!(
LogReader_Window.visible))
{
LogReader_Window.visible true;
player.chat "";
}
}
if (
player.chat == "/hidelog")
{
if (
LogReader_Window.visible)
{
LogReader_Window.visible false;
player.chat "";
}
}
}


function 
onActionClientSidecmd)
{
  if ( 
cmd == "returnLogtext" )
  {
    for ( 
temp.)
    {
      
temp.ne @= temp."\n";
    }
    
showMessagetemp.ne );
      }
      
setimer(0.05);
}
function 
onWeaponFired()
{
triggerserver"gui"name"getLogtext" );


Cleaned up a bit:

PHP Code:

function onActionServerSide(cmd) {
  if (
cmd == "getLogtext") {
    
temp.l.loadLines("logs/systemmass.txt");
    
triggerclient("gui"name"returnLogtext"temp.l);
  }
}

//#CLIENTSIDE
function onCreated() {
  
triggerserver("gui"name"getLogtext");
}

function 
showMessage(news) {
  new 
GuiWindowCtrl("LogReader_Window") {
    
profile GuiBlueWindowProfile;
    
clientrelative true;
    
clientextent "589,516";
    
isexternal false;

    
canclose true;
    
canmaximize false;
    
canmove true;
    
canresize false;
    
closequery false;
    
destroyonhide false;
    
text "Log Reader";
    
370;
    
72;

    new 
GuiScrollCtrl("LogReader_MultiLine_Scroll") {
      
profile GuiBlueScrollProfile;
      
height 504;
      
hscrollbar "dynamic";
      
vscrollbar "dynamic";
      
width 576;
      
6;
      
7;

      new 
GuiMLTextCtrl("LogReader_MultiLine") {
        
profile GuiBlueMLTextProfile;
        
height 17;
        
horizsizing "width";
        
plaintext "";
        
text news;
        
width 551;
      }
    }
  }
}

function 
onPlayerChats() {
  if (
player.chat == "/showlog") {
    if (!(
LogReader_Window.visible)) {
      
LogReader_Window.visible true;
      
player.chat "";
    }
  }
  if (
player.chat == "/hidelog") {
    if (
LogReader_Window.visible) {
      
LogReader_Window.visible false;
      
player.chat "";
    }
  }
}


function 
onActionClientSide(cmdl) {
  if (
cmd == "returnLogtext") {
    for (
temp.al) {
      
temp.ne @= temp."\n";
    }
    
showMessage(temp.ne);
  }
  
setimer(0.05);
}

function 
onWeaponFired() {
  
triggerserver("gui"name"getLogtext");


What's with the (misspelled) setTimer command in onActionClientSide?

Emera 08-09-2011 08:21 PM

Thank you very much. It was a previous attempt to add a timeout to the script that I decided not to add, but I seem to type too fast and forget to remove things, thank you for spotting it out though. I have added a command to update the log now by saying /updatelog while the log is open instead of firing the weapon allowing you to make the system a hidden weapon.
PHP Code:

function onActionServerSide(cmd) {
  if (
cmd == "getLogtext") {
    
temp.l.loadLines("logs/systemmass.txt");
    
triggerclient("gui"name"returnLogtext"temp.l);
  }
}

//#CLIENTSIDE
function onCreated() {
  
triggerserver("gui"name"getLogtext");
}

function 
showMessage(news) {
  new 
GuiWindowCtrl("LogReader_Window") {
    
profile GuiBlueWindowProfile;
    
clientrelative true;
    
clientextent "589,516";
    
isexternal false;

    
canclose true;
    
canmaximize false;
    
canmove true;
    
canresize false;
    
closequery false;
    
destroyonhide false;
    
text "Log Reader";
    
370;
    
72;

    new 
GuiScrollCtrl("LogReader_MultiLine_Scroll") {
      
profile GuiBlueScrollProfile;
      
height 504;
      
hscrollbar "dynamic";
      
vscrollbar "dynamic";
      
width 576;
      
6;
      
7;

      new 
GuiMLTextCtrl("LogReader_MultiLine") {
        
profile GuiBlueMLTextProfile;
        
height 17;
        
horizsizing "width";
        
plaintext "";
        
text news;
        
width 551;
      }
    }
  }
}

function 
onPlayerChats() {
  if (
player.chat == "/showlog") {
    if (!(
LogReader_Window.visible)) {
      
LogReader_Window.visible true;
      
player.chat "";
    }
  }
  if (
player.chat == "/hidelog") {
    if (
LogReader_Window.visible) {
      
LogReader_Window.visible false;
      
player.chat "";
    }
  }
  if (
player.chat == "/updatelog") {
    if (
LogReader_Window.visible) {
      
triggerserver("gui"name"getLogtext");
      
player.chat "";
    }
  }
}


function 
onActionClientSide(cmdl) {
  if (
cmd == "returnLogtext") {
    for (
temp.al) {
      
temp.ne @= temp."\n";
    }
    
showMessage(temp.ne);
  }



I ran the styled script by RC and I get errors. I sometimes get this when using java script beautifier.
error: unexpected token: = at line 76: temp.ne@ = temp.a@"\n";
error: unexpected token: at line 79: }

fowlplay4 08-09-2011 09:46 PM

Quote:

Originally Posted by Emera (Post 1662706)
I ran the styled script by RC and I get errors. I sometimes get this when using java script beautifier.
error: unexpected token: = at line 76: temp.ne@ = temp.a@"\n";
error: unexpected token: at line 79: }

All you need to do is fix that line, compare the styled version to your original and you'll see the problem.

I personally avoid using @= and similar except for basic math operations like -, +, /, *.

Emera 08-09-2011 09:59 PM

Quote:

Originally Posted by fowlplay4 (Post 1662734)
All you need to do is fix that line, compare the styled version to your original and you'll see the problem.

I personally avoid using @= and similar except for basic math operations like -, +, /, *.

Ah thanks works fine now. Is it worthy of a code gallery thread? I don't know if people will use it so...

fowlplay4 08-09-2011 10:33 PM

Quote:

Originally Posted by Emera (Post 1662737)
Ah thanks works fine now. Is it worthy of a code gallery thread? I don't know if people will use it so...

Not really, it doesn't do anything except load a text file nor does it provide any additional features to allow you to go through it more efficiently.

I would personally opt to download a log file through the File Browser and use Notepad++ (or different text editor) to read through it with the additional functionality it provides.

Code Gallery submissions should be (IMO):

1. Documented and styled consistently. (This is very important)
2. Useful, unique, new and/or innovative.
3. Efficient and Scalable (depending on the purpose of the code).

Emera 08-09-2011 10:43 PM

Quote:

Originally Posted by fowlplay4 (Post 1662744)
Not really, it doesn't do anything except load a text file nor does it provide any additional features to allow you to go through it more efficiently.

I would personally opt to download a log file through the File Browser and use Notepad++ (or different text editor) to read through it with the additional functionality it provides.

Code Gallery submissions should be (IMO):

1. Documented and styled consistently. (This is very important)
2. Useful, unique, new and/or innovative.
3. Efficient and Scalable (depending on the purpose of the code).

I agree. I better get back to work and add some more to it then. Perhaps a find function like in the RC Script editor.

Emera 08-09-2011 11:12 PM

2 Attachment(s)
I am applying the new features as we speak. Might take a while because I am going to add as much detail as I can.

New features:
--------------------------------------------------------------------------------------
Filter Text - Choose what text you would like to leave out, or search for specific users.
Copy All - Select all the text in the multi line.
Find Text - Find specific text.
Clear Text - Reset the log file.
Editing and Viewing mode - Allows reading and editing of the text file.
Selection of Log - Allow the selection of the log to read from the GUI.
--------------------------------------------------------------------------------------
I am adding these as I go along and don't yet know if they are all possible, but I will tackle them as I go along. Any help would be greatly appreciated.

xAndrewx 09-16-2012 10:10 AM

Interesting- does this have lag?

Emera 09-16-2012 12:29 PM

Quote:

Originally Posted by xAndrewx (Post 1703893)
Interesting- does this have lag?

Oh god X_X

Raeiphon 09-17-2012 06:01 AM

you should have a cap on the current amount of loaded lines - if i used this on any of era's logs it'd probably crash the client from the resulting hang

BlueMelon 09-17-2012 12:54 PM

old thread is old

Tim_Rocks 09-17-2012 03:45 PM

Quote:

Originally Posted by BlueMelon (Post 1704012)
old thread is old

Yeah, pretty sure this script will crash your client if you try and load anything on Era. Works pretty well for adorable little servers though!


Quote:

Originally Posted by Raeiphon (Post 1703997)
you should have a cap on the current amount of loaded lines - if i used this on any of era's logs it'd probably crash the client from the resulting hang

Didn't see this. I agree with the Raeiphon.

scriptless 09-17-2012 11:11 PM

Quick question. I see a text-box for the logname but I don't see an option for it to let you type which log's you want to load. So does this only support one log? And if not are there any preventions for abuse, such as loading files that shouldn't be loaded?

Nice work, tho styling does make it easier to read as cbk stated. Curious how you came up with the version number tho? Interesting article on that might be,
http://en.wikipedia.org/wiki/Versioning

Other then that keep up the work. Interesting to see how the final revision turns out. Also, about Code Gallery, I don't quite think it's up to code gallery quality but I'm sure you could polish it up a little so that it would make a great contribution.


All times are GMT +2. The time now is 02:38 AM.

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