Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   Server Flag Adder (https://forums.graalonline.com/forums/showthread.php?t=134264366)

Emera 08-26-2011 04:33 PM

Server Flag Adder
 
2 Attachment(s)
I have finally completed my code! Thank you to everybody who contributed towards the completion of the code by helping me out on various threads I have created about the development of this tool.

The Tool
The Server Flag Adder is a tool for displaying all of the current server flags in a nice GUI menu. Within the menu, you have the option to add flags to the server without creating them through a script. It displays the flags you already have present on your server with a Text List control in a nice little interface. I myself like to use GUI's as much as I can as it makes whatever you are developing nice and tidy (if you design the GUI properly!)

To open the GUI, all the player has to do is chat "/flagadder". Obviously, you can change that command to whatever you prefer or even allow it to open after a certain key has been pressed.

CODE
PHP Code:

function onCreated() {
  
this.allowed = {
    
"McChucken""Other community name"
  
};
}
function 
onActionServerside() {
  if (
params[0] == "addflags")  { 
    if (
player.communityname in this.allowed) {
      
serverr.(@params[1]) = params[2];
    }  
  }
}

//#CLIENTSIDE
function addrowsys_Button1.onAction() {
  new 
GuiWindowCtrl("Extent_Window1") {
    
profile GuiBlueWindowProfile;
    
clientrelative true;
    
style $pref::Video::defaultguistyle;
    
clientextent "176,118";
    
canmaximize false;
    
canminimize false;
    
canmove true;
    
canresize true;
    
closequery false;
    
destroyonhide true;
    
text "Add a flag";
    
517;
    
209;
    new 
GuiTextEditCtrl("Extent_TextEdit1") {
      
profile GuiBlueTextEditProfile;
      
height 20;
      
width 80;
      
7;
      
19;
    }
    new 
GuiTextEditCtrl("Extent_TextEdit2") {
      
profile GuiBlueTextEditProfile;
      
height 20;
      
width 80;
      
7;
      
59;
    }
    new 
GuiTextCtrl("Extent_Text1") {
      
profile GuiBlueTextProfile;
      
height 20;
      
text "Flag Content";
      
width 73;
      
92;
      
58;
    }
    new 
GuiTextCtrl("Extent_Text2") {
      
profile GuiBlueTextProfile;
      
height 20;
      
text "Title / Name";
      
width 69;
      
93;
      
18;
    }
    new 
GuiButtonCtrl("Extent_Button1") {
      
profile GuiBlueButtonProfile;
      
height 22;
      
text "Add Flag";
      
width 164;
      
6;
      
90;
    }
  }
}

function 
CreateGui() {
  new 
GuiWindowCtrl("addrowsys_Window1") {
    
profile GuiBlueWindowProfile;
    
clientrelative true;
    
clientextent "367,238";
    
isexternal false;
    
style $pref::Video::defaultguistyle;
    
canmaximize false;
    
canminimize false;
    
canmove true;
    
canresize false;
    
closequery false;
    
destroyonhide true;
    
text "Server Flag Editor";
    
480;
    
84;
    new 
GuiControl("Border1") {
      
useownprofile true;
      
profile.border 0;
      
profile.opaque true;
      
profile.fillColor = {
        
163194212120
      
};
      
width 367;
      
height 238;
      
0;
      
0;
    }
    new 
GuiButtonCtrl("addrowsys_Button1") {
      
profile GuiBlueButtonProfile;
      
height 24;
      
text "+";
      
width 24;
      
335;
      
3;
      
hint "Add flag";
    }
    new 
GuiButtonCtrl("addrowsys_Button3") {
      
profile GuiBlueButtonProfile;
      
height 24;
      
text "?";
      
width 24;
      
285;
      
3;
      
hint "help";
    }
    new 
GuiButtonCtrl("addrowsys_Button4") {
      
profile GuiBlueButtonProfile;
      
height 24;
      
text "^";
      
width 24;
      
310;
      
3;
      
hint "Update";
    }
    new 
GuiScrollCtrl("addrowsys_TextList1_Scroll") {
      
profile GuiBlueScrollProfile;
      
hscrollbar "alwaysOff";
      
vscrollbar "dynamic";
      
width 354;
      
6;
      
32;
      new 
GuiTextListCtrl("addrowsys_TextList1") {
        
profile GuiBlueTextListProfile;
        
height 34;
        
horizsizing "width";
        
sortcolumn 167550464;
        
width 350;
      }
    }
    new 
GuiTextCtrl("addrowsys_Text1") {
      
profile GuiBlueTextProfile;
      
height 20;
      
text "Server Flag Adder.";
      
width 305;
      
9;
      
6;
    }
  }
}

function 
addrowsys_Button4.onAction() {
  
getflags();
}

function 
Extent_Button1.onAction() {
  
addflags();
}

function 
addrowsys_Button3.onAction() {
  
say2("You can add rows#bto the GUI by pressing#bthe + button.#bYou can update the flag#bscreen by pressing the ^ button.");
}

function 
GetFlags() {
  
addrowsys_TextList1.clearrows();
  for (
temp.flagserverr.getdynamicvarnames()) {
    
addrowsys_TextList1.addrow(temp.counttemp.flagtemp.value serverr.(@temp.flag));
    
temp.count++;
  }
}

function 
AddFlags() {
  
triggerserver("gui"this.name"addflags"Extent_TextEdit1.textExtent_TextEdit2.text);
  
getflags();
}

function 
OpenGui() {
  
creategui();
  
addflags();
}

function 
ChatBar.onAction() {   
  if (
ChatBar.text.trim() == "/flagadder") {   
    
OpenGui(); //Opens the GUI. 
    
ChatBar.text ""// Clear the chatbar so /flagadder isn't chatted out loud. 
  
}   


The Graal Pastebin file can be found here.
Have fun!

0PiX0 08-26-2011 05:08 PM

Good job finishing your script. :) I have a few suggestions, if you feel like improving it.

Before modifying the serverr flag, verify that the player is who it should be. An abusive player could manipulate their client into sending a trigger to this weapon and modify any serverr flag they wish.

PHP Code:

function onActionServerside() {
  if (!(
player.communityname in serveroptions.staff.tokenize(",")))
    return;
  if (
params[0] == "addflags"serverr.(@params[1]) = params[2];


Also, please use
PHP Code:

function ChatBar.onAction() { 
  if (
ChatBar.text.trim() == "/flagadder") { 
    
OpenGui(); //Opens the GUI. 
  



rather than onPlayerChats for chat commands.

Emera 08-26-2011 05:39 PM

Replaced the method for activating the GUI and also added some security. It reads from this.allowed instead of the server options. I don't want every single staff member to have access to this script.

PHP Code:

//#CLIENTSIDE
function onCreated() {
  
this.allowed = {
    
"Community name 1""Community name 2"
  
};


Then in the main script

PHP Code:

function Extent_Button1.onAction() {
  if (
player.communityname in this.allowed) {
    
addflags();
  }


So you have to be in the this.allowed to be able to use the button to add flags.

And thank you for helping me out :D

EDIT: Didn't want to double post. It now recognizes your GUI style and adapts its design to fit with it. Say if I was using Toon.wba (best theme ever), the theme would become toon.wba

0PiX0 08-26-2011 07:11 PM

Quote:

Originally Posted by Emera (Post 1665554)
Replaced the method for activating the GUI and also added some security. It reads from this.allowed instead of the server options. I don't want every single staff member to have access to this script.

The security check still should be on the server-side. Anything on the client-side should be treated as if it could possibly be manipulated.

Emera 08-26-2011 11:11 PM

Quote:

Originally Posted by 0PiX0 (Post 1665575)
The security check still should be on the server-side. Anything on the client-side should be treated as if it could possibly be manipulated.

Can I still use
PHP Code:

function onActionServerside() {
  
this.allowed = {"whatever"};

//Rest of code 

Or is there a different way?

fowlplay4 08-26-2011 11:15 PM

Quote:

Originally Posted by Emera (Post 1665621)
Can I still use
PHP Code:

function onActionServerside() {
  
this.allowed = {"whatever"};

//Rest of code 


Yeah.

cbk1994 08-26-2011 11:30 PM

Quote:

Originally Posted by Emera (Post 1665621)
Can I still use
PHP Code:

function onActionServerside() {
  
this.allowed = {"whatever"};

//Rest of code 

Or is there a different way?

If you're going to use a this. variable, you might as well define it in onCreated instead of onActionServerSide.

Emera 08-26-2011 11:34 PM

Fixed. Added to first post.
PHP Code:

function onActionServerside() {
this.allowed = {
    
"McChucken",
    
"Other community name"
  
};
  if (
params[0] == "addflags")
    if (
player.communityname in this.allowed) {
      
serverr.(@params[1]) = params[2];
    }



fowlplay4 08-26-2011 11:44 PM

Don't do what you did:

PHP Code:

if (statement) if (otherstatement) {



Either do:

PHP Code:

if (statement) {
  if (
otherstatement) {

  }


or even (I prefer using two ifs though):

PHP Code:

if (statement && otherstatement) {



The above two are much more readable and will be easier to modify in the future. When you modify the code.

Also:

PHP Code:

function ChatBar.onAction() {  
  if (
ChatBar.text.trim() == "/flagadder") {  
    
OpenGui(); //Opens the GUI.
    
ChatBar.text ""// Clear the chatbar so /flagadder isn't chatted out loud.
  
}  



Emera 08-26-2011 11:55 PM

Quote:

Originally Posted by fowlplay4 (Post 1665628)
Don't do what you did:

PHP Code:

if (statement) if (otherstatement) {



Either do:

PHP Code:

if (statement) {
  if (
otherstatement) {

  }


or even (I prefer using two ifs though):

PHP Code:

if (statement && otherstatement) {



The above two are much more readable and will be easier to modify in the future. When you modify the code.

Also:

PHP Code:

function ChatBar.onAction() {  
  if (
ChatBar.text.trim() == "/flagadder") {  
    
OpenGui(); //Opens the GUI.
    
ChatBar.text ""// Clear the chatbar so /flagadder isn't chatted out loud.
  
}  



Oops that was an error. Fixed now.

fowlplay4 08-27-2011 12:00 AM

Quote:

Originally Posted by Emera (Post 1665631)
Oops that was an error. Fixed now.

No it's not. You're still only using one set of {}'s for two if statements.

0PiX0 08-27-2011 12:47 AM

Quote:

Originally Posted by Emera (Post 1665544)
PHP Code:

function onActionServerside() {
  
this.allowed = {
    
"McChucken""Other community name"
  
};
  if (
params[0] == "addflags")  { 
    if (
player.communityname in this.allowed) {
    
serverr.(@params[1]) = params[2];
    }  
  }



It's not necessary to set this.allowed every time the onActionServerSide event is invoked.

PHP Code:

function onCreated() {
  
//set this.allowed to whatever
}

function 
onActionServerSide() {
  
//stuff




All times are GMT +2. The time now is 02:36 PM.

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