Author Topic: My Script ( agreement rules)  (Read 1281 times)

In prompt events, it turns out that MessageBoxNo and MessageBoxCancel are not being parented

Code: [Select]
package PromptEvents
{
function serverCmdMessageBoxCancel(%cl)
{
%cl.processPrompt(0);
}

function serverCmdMessageBoxNo(%cl)
{
%cl.processPrompt(0);
}
};
activatePackage(PromptEvents);

And neither is it in Furling's code

Code: [Select]
    function serverCmdMessageBoxNo(%cl) //This is the serverCmd that is done when they press no. (hopefully)
    {
    messageAll('',"\c3Host \c2kicked \c3" @ %cl.getPlayerName() @ "\c2(ID:" SPC %cl.getBLID() @ ") \c6for not agree with Host's Rules.");
    %cl.delete("You were not agree with Host's Rules.");
    }

Says xalos -
Quote
Xalos: Perhaps, as you will happen to notice is the case with HIS CODE
Xalos: there is another mod which isn't actually PARENTING MessageBoxNo
Xalos: because with ONE mod using it, you can get away with that
Xalos: because it doesn't DO anything

And according to a changelog

Quote from: v10 to v11
If they click "no" commandToServer('MessageBoxNo');

Apparently no other arguments are passed
« Last Edit: June 25, 2013, 09:10:15 AM by Pacnet2012³ »

I did tested on Ded server does not work only yes, not "NO" work. how I can remove cmd NON-abused?
CmdMessageBoxNo
CmdMessageBoxYes
these are cmd.
But Solo server work. I agree with xalos that cmd are abused, how I can fix on non-abuse?

EDIT fix code:
Code: [Select]
$Rules_File = "config/server/agreementrules.txt";
$DefaultRules_File = "Add-ons/Server_AgreementRules/defaultagreementrules.txt";

function loadRuleFile()
{
    %file = new fileObject(fileStream);
    %file.openForRead($Rules_File);
    %file.readLine();
    //for some reason, isFile is not working
    if(%file.isEOF())
    {
    %from = new fileObject();
    %to = new fileObject();
    %from.openForRead($DefaultRules_File);
    %to.openForWrite($Rules_File);
   
    while(!%from.isEOF())
        %to.writeLine(%from.readLine());
    %to.close();
    %from.close();
    %to.delete();
    %from.delete();
    }
    %file.close();
    %file.delete();
    %file = new fileObject();
    %file.openForRead($Rules_File);
    $Rules_Title = %file.readLine(); //The first line of the file is the title.
    $Rules_Body = %file.readLine(); //Define $Rules_Body
    while(!%file.isEOF()) //Keep reading lines until we reach the end of the file.
    $Rules_Body = trim($Rules_Body NL %file.readLine()); //Add the next line to the rules body. Doing the trim function removes things like spaces and tabs that we don't want.
    %file.close(); //Close the file; important.
    %file.delete(); //Delete the file object.
}
loadRuleFile();

package Rules //we want to make a package
{
    function GameConnection::OnClientEnterGame(%this)
    {
    %this.schedule(2500, sendRules);
    Parent::OnClientEnterGame(%this);
    }

    function GameConnection::sendRules(%this)
    {
    commandToClient(%this,'messageBoxYesNo', $Rules_Title, $Rules_Body,'AcceptRules'); //Send the messagebox properly
    }

    function commandToServer('MessageBoxNo');(%cl) //Unsure if this is works, but I think it should. Supposedly this is done when they press yes.
    {
    messageAll('',"\c3" @ %cl.getPlayerName() @ "\c2(ID:" SPC %cl.getBLID() @ ") \c6agreed with Host's Rules.");
           
    }

    function commandToServer('MessageBoxNo');(%cl) //This is the serverCmd that is done when they press no. (hopefully)
    {
    messageAll('',"\c3Host \c2kicked \c3" @ %cl.getPlayerName() @ "\c2(ID:" SPC %cl.getBLID() @ ") \c6for disagree with Host's Rules.");
    %cl.delete("You were disagree with Host's Rules.");
    }
};
activatePackage(Rules);

I don't think it would be fair to release it since the very large majority of it is Kalphiter's code.

I don't think it would be fair to release it since the very large majority of it is Kalphiter's code.
He will get part of this code credits.

I test this has a few isussed:
1.Solo Server-worked
2.Internet Server-worked
3.Dedicated server-worked
Disable Prompt event- worked
Enable Prompt event- not work (NO)

« Last Edit: June 25, 2013, 11:07:37 AM by Furling² »

I added the anti-abuse check and fixed a major syntax error as well as a mild grammar problem and added the required parent

Code: [Select]
$Rules_File = "config/server/agreementrules.txt";
$DefaultRules_File = "Add-ons/Server_AgreementRules/defaultagreementrules.txt";

function loadRuleFile()
{
    %file = new fileObject(fileStream);
    %file.openForRead($Rules_File);
    %file.readLine();
    //for some reason, isFile is not working
    if(%file.isEOF())
    {
    %from = new fileObject();
    %to = new fileObject();
    %from.openForRead($DefaultRules_File);
    %to.openForWrite($Rules_File);
    
    while(!%from.isEOF())
        %to.writeLine(%from.readLine());
    %to.close();
    %from.close();
    %to.delete();
    %from.delete();
    }
    %file.close();
    %file.delete();
    %file = new fileObject();
    %file.openForRead($Rules_File);
    $Rules_Title = %file.readLine(); //The first line of the file is the title.
    $Rules_Body = %file.readLine(); //Define $Rules_Body
    while(!%file.isEOF()) //Keep reading lines until we reach the end of the file.
    $Rules_Body = trim($Rules_Body NL %file.readLine()); //Add the next line to the rules body. Doing the trim function removes things like spaces and tabs that we don't want.
    %file.close(); //Close the file; important.
    %file.delete(); //Delete the file object.
}
loadRuleFile();

package Rules //we want to make a package
{
    function GameConnection::OnClientEnterGame(%this)
    {
    %this.schedule(2500, sendRules);
    Parent::OnClientEnterGame(%this);
    }

    function GameConnection::sendRules(%this)
    {
      %this.gotRules = true;
    commandToClient(%this,'messageBoxYesNo', $Rules_Title, $Rules_Body,'AcceptRules'); //Send the messagebox properly
    }

    function serverCmdAcceptRules(%cl) //Unsure if this is works, but I think it should. Supposedly this is done when they press yes.
    {
       if(!%cl.acceptedRules)
       {
          messageAll('',"\c3" @ %cl.getPlayerName() @ "\c2(ID:" SPC %cl.getBLID() @ ") \c6agreed with Host's Rules.");
          %cl.acceptedRules = true;
       }    
    }

    function serverCmdMessageBoxNo(%cl) //This is the serverCmd that is done when they press no. (hopefully)
    {
     if(%client.gotRules)
    {
         if(!%client.acceptedRules)
        {
        messageAll('',"\c3Host \c2kicked \c3" @ %cl.getPlayerName() @ "\c2(ID:" SPC %cl.getBLID() @ ") \c6for disagreeing   with Host's Rules.");
        %cl.delete("You disagreed with Host's Rules.");
        }
    }
     parent serverCmdMessageBoxNo(%cl);
    }
};
activatePackage(Rules);



And I think prompt events itself can be fixed by changing this
Code: [Select]
package PromptEvents
{
function serverCmdMessageBoxCancel(%cl)
{
%cl.processPrompt(0);
}

function serverCmdMessageBoxNo(%cl)
{
%cl.processPrompt(0);
}
};
activatePackage(PromptEvents);

into this -

Code: [Select]
package PromptEvents
{
function serverCmdMessageBoxCancel(%cl)
{
%cl.processPrompt(0);
                parent serverCmdMessageBoxCancel(%cl);
}

function serverCmdMessageBoxNo(%cl)
{
%cl.processPrompt(0);
                parent serverCmdMessageBoxNo(%cl);
}
};
activatePackage(PromptEvents);


  
« Last Edit: June 25, 2013, 10:48:52 AM by Pacnet2012³ »

-snip-
That will still allow the player to reject the rules even after they have been accepted. You also didn't check for anything when you sent the messagebox so the player would be kicked by every messageyesno box they receive.

Code: [Select]
$Rules_File = "config/server/agreementrules.txt";
$DefaultRules_File = "config/server/add-ons/agreementrules.txt";

function loadRuleFile()
{
    %file = new fileObject(fileStream);
    %file.openForRead($Rules_File);
    %file.readLine();
    //for some reason, isFile is not working
    if(%file.isEOF())
    {
    %from = new fileObject();
    %to = new fileObject();
    %from.openForRead($DefaultRules_File);
    %to.openForWrite($Rules_File);
    
    while(!%from.isEOF())
        %to.writeLine(%from.readLine());
    %to.close();
    %from.close();
    %to.delete();
    %from.delete();
    }
    %file.close();
    %file.delete();
    %file = new fileObject();
    %file.openForRead($Rules_File);
    $Rules_Title = %file.readLine(); //The first line of the file is the title.
    $Rules_Body = %file.readLine(); //Define $Rules_Body
    while(!%file.isEOF()) //Keep reading lines until we reach the end of the file.
    $Rules_Body = trim($Rules_Body NL %file.readLine()); //Add the next line to the rules body. Doing the trim function removes things like spaces and tabs that we don't want.
    %file.close(); //Close the file; important.
    %file.delete(); //Delete the file object.
}
loadRuleFile();

package AgreementRules //we want to make a package
{
    function GameConnection::OnClientEnterGame(%this)
    {
    %this.schedule(2500, sendRules);
    Parent::OnClientEnterGame(%this);
    }

    function GameConnection::sendRules(%this)
    {
    commandToClient(%this,'messageBoxYesNo', $Rules_Title, $Rules_Body,'AcceptRules'); //Send the messagebox properly
    %this.hasRecievedRules = 1;
    }

    function serverCmdAcceptRules(%cl) //Unsure if this is works, but I think it should. Supposedly this is done when they press yes.
    {
        if(%cl.hasAgreed)
            return;
        messageAll('',"\c3" @ %cl.getPlayerName() @ "\c2(ID:" SPC %cl.getBLID() @ ") \c6agreed with the Host's Rules.");
        %cl.hasAgreed = 1;
    }

    function serverCmdMessageBoxNo(%cl) //This is the serverCmd that is done when they press no. (hopefully)
    {
        if(%cl.hasRecievedRules)
        {
            if(%cl.hasAgreed)
                return;
            messageAll('',"\c3Host \c2kicked \c3" @ %cl.getPlayerName() @ "\c2(ID:" SPC %cl.getBLID() @ ") \c6for not agreeing with Host's Rules.");
            %cl.delete("You did not agree to the host's rules.");
        }
        else
            Parent::serverCmdMessageBoxNo(%cl);
    }
};
activatePackage(AgreementRules);
« Last Edit: June 26, 2013, 06:40:11 AM by Danny Boy »

That will still allow the player to reject the rules even after they have been accepted. You also didn't check for anything when you sent the messagebox so the player would be kicked by every messageyesno box they receive.

Code: [Select]
-sinp-
Disable Prompt event- worked
Enable Prompt event- not work (NO button)

I think that would have something to do with the prompt events rather than your script.

Disable Prompt event- worked
Enable Prompt event- not work (NO button)
You have to fix Prompt Events manually because it does not parent MessageBoxCancel or MessageBoxNo