The online racing simulator
#1 - Krayy
[CODE] List and Save Usergroups (particularly the admin group)
Hi all,

Heres a patch file that will add the ability to get a comma seperated list of users in a group, along with the ability to save a usergroup to a disk based file. I have included code below to add to the LFSLapper.lpr file to enable you to add and delete Admins while in game.

Note that Lapper can only return strings, floats or ints to the GLScript parser, so the user lists are returned in a single comma separated string. You will need to use substr or split as I have done to access each username in turn.

PS: The patch file also adds code to allow the rcae host (UCID 0) to !start, !stop and !reload lapper. This is because we use the LFS Server on a dedicated host and this way we don't have to run another instance of LFS to get it up and running.

Add this code in the main "SWITCH( $command )" CASE statement:

<?php 
        
CASE "!listgroup":
            IF( 
UserInGroup"admin",$userName ) == )
            
THEN
                
IF( $argv != "" THEN
                    privMsg
"^3Current members of group: " $argv "^8" );
                    
PrintUserGroup ($argv);
                ELSE
                    
privMsg"^3You must specify a user group to list^8" );
                ENDIF
            ENDIF
            BREAK;
        CASE 
"!admins":
            IF( 
UserInGroup"admin",$userName ) == )
            
THEN
                
IF( $argv != "" THEN
                    $idxSpace 
indexOf$argv" ");
                    IF( 
$idxSpace != -THEN
                        $option 
subStr$argv,0,$idxSpace );
                        
$argv trimsubStr$argv,$idxSpace ) );
                        SWITCH( 
$option )
                            CASE 
"add":
                                
MoveUserToGroup"admin" $argv);
                                
SaveGroupToFile"admin""./admin.txt" );
                            BREAK;
                            CASE 
"del":
                                
RemoveUserFromGroup"admin" $argv);
                                
SaveGroupToFile"admin""./admin.txt" );
                            BREAK;
                            DEFAULT:
                                
privMsg"No such option for this command: " $option );
                            BREAK;
                        ENDSWITCH
                    ELSE
                        
privMsg"Command needs more parameters" );
                    ENDIF
                ENDIF
            ENDIF
            
privMsg"^3Current Admins:^8" );
            
PrintUserGroup ("admin");
            BREAK;
?>

Add this code after the EndEvent statement at the end of that ENDSWITCH:

<?php 
Sub PrintUserGroup 
($UserGroup)
    
$IsNotBlank 1;
    
$GroupIndex 0;
    WHILE (
$IsNotBlank == 1)
        
$GroupUser=splitListGroupUsers($UserGroup),",",$GroupIndex );
        IF ( 
$GroupUser != ""THEN
            privmsg
($GroupUser);
            
$GroupIndex $GroupIndex 1;
        ELSE
            
$IsNotBlank 0;
        ENDIF
    ENDWHILE
EndSub
?>


Happy racing.
Attached files
krayy_usergroup_patch.txt - 4.9 KB - 567 views
Thanks.
i have copy everything from the file u have added.
and after that i have tried if SaveGroupToFile works.
but the code after ELSE (!addadmin) and the code after the 2nd THEN (!readmin) doesnt work anymore.
!addadmin and !readmin does work without SaveGroupToFile( "UserAdmin", "./UserAdmin.txt" );

this is from the errorfile:
savegrouptofile' is not a Lapper function
Function 'onmso' script aborted



CASE "!addadmin":
IF( UserInGroup( "UserAdmin",$userName ) == 1 )
THEN
IF( UserInGroup( "UserAdmin",$argv ) == 1 )
THEN
privMsg( "^7User is already admin!!!");
ELSE
MoveUserToGroup( "UserAdmin",$argv );
SaveGroupToFile( "UserAdmin", "./UserAdmin.txt" );
privMsg( "^7Added New Admin succesfully!!");
ENDIF
ENDIF
BREAK;
CASE "!readmin":
IF( UserInGroup( "UserAdmin",$userName ) == 1 )
THEN
IF( UserInGroup( "UserAdmin",$argv ) == 1 )
THEN
privMsg( "^7Removed User succesfully!!");
RemoveUserFromGroup( "UserAdmin",$argv );
SaveGroupToFile( "UserAdmin", "./UserAdmin.txt" );
ELSE
privMsg( "^1User not found in UserAdmin file");
ENDIF
ENDIF
BREAK;

#4 - Krayy
Quote from Bass-Driver :i have copy everything from the file u have added.
and after that i have tried if SaveGroupToFile works.
but the code after ELSE (!addadmin) and the code after the 2nd THEN (!readmin) doesnt work anymore.
!addadmin and !readmin does work without SaveGroupToFile( "UserAdmin", "./UserAdmin.txt" );

this is from the errorfile:
savegrouptofile' is not a Lapper function
Function 'onmso' script aborted

Heya,

Okay, the code in the post is an example of what you can add to the *.lpr files to support usergroup save/listing.

The attachment (the patch file) is what you need to use to alter the source code (this pathc file is from TortoiseSVN, but can be used with any othe SVN app or manually).

The errors that you are getting are because the source code and LPSLapper.exe has not been rebuilt yet. To do this you will need to have Visual C# Express Edition installed, and have the LFSLapper source code extracted to a directory.

The patch file lists the files that are altered in the LFSLapper/src directory, the code lines to add (+) and lines that should be removed or commented (-). Make these adjustments then open the LFSLapper.csproj file in Visual C# and hit the F6 key to recompile. You will now find a new .exe file in the Release directory. Copy that over your old LFSLapper.exe are you're away laughing
k
i cant compile LFSLapper.csproj in visual C#
when i open LFSLapper.csproj then Visual C# said its a LFSLapper.csproj.user file
is this correct??

this what i get when i open the file

<

Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectView>ProjectFiles</ProjectView>
<PublishUrlHistory>publish\</PublishUrlHistory>
<InstallUrlHistory>
</InstallUrlHistory>
<SupportUrlHistory>
</SupportUrlHistory>
<UpdateUrlHistory>
</UpdateUrlHistory>
<BootstrapperUrlHistory>
</BootstrapperUrlHistory>
<FallbackCulture>fr-FR</FallbackCulture>
<VerifyUploadedFiles>false</VerifyUploadedFiles>
</PropertyGroup>
</Project>

#6 - Krayy
Quote from Bass-Driver :k
i cant compile LFSLapper.csproj in visual C#
when i open LFSLapper.csproj then Visual C# said its a LFSLapper.csproj.user file
is this correct??

You're trying to open the LFSLapper.csproj.user file, not the LFSLapper.csproj file. Turn off "Hide extensions of known files" in Windows Explorer.
k got it
when i want to debug it said

the working directory does not exist
D\Dev\Devinsim\lapper\LFSLapper\LFSLapperBin\Release\'.

is it possible to send your LFSLapper.exe to me via my email.
thx
#8 - Krayy
You don't need to debug it, just hit F6 to compile it.

BUT...when you open the LFSLapper.csproj file, go to the Project->LFSLapper Properties menu, go to the Debug tab and set the path to ..\LFSLapperBin\Release\ (you may need to create this directory). Set the Ouput Path in the Build tab to the same.
k done
good news the code works
bad news : it doesnt save the users and i need to login everytime when i start lapper .i did putt myself manualy in the UserAdmin file. but still i need to login as admin when i start lapper.
lol i have mine locked up so tight u have to be a admin or a beta tester to do the !login command itself
Quote from Bass-Driver :k done
good news the code works
bad news : it doesnt save the users and i need to login everytime when i start lapper .i did putt myself manualy in the UserAdmin file. but still i need to login as admin when i start lapper.

What version of lapper are you using?

Also, I'm not sure why you're using "UserAdmin" instead of "admin" as the group, as Lapper has quite a few functions that require you to be in the "admin" group. (Unless you did a global search/replace of course). Or is there a specific function that the UserAdmin group does?
Nvm
9/12/2009 9:27:00 PM -> Syntax error in cfg file "LFSLapper.lpr" at line #1745
Token not catched
Function 'printusergroup' script aborted
Quote from Krayy :What version of lapper are you using?

Also, I'm not sure why you're using "UserAdmin" instead of "admin" as the group, as Lapper has quite a few functions that require you to be in the "admin" group. (Unless you did a global search/replace of course). Or is there a specific function that the UserAdmin group does?

problem solved. it works now
i think i did something wrong with copy the code.
!listgroup crashed after showing users in file
!admin doesnt work at all(lapper crash)
Quote from Fire_optikz001 :9/12/2009 9:27:00 PM -> Syntax error in cfg file "LFSLapper.lpr" at line #1745
Token not catched
Function 'printusergroup' script aborted

Try this .exe and see if that works for you.
Attached files
LFSLapper_save_exe.zip - 107.8 KB - 676 views
9/13/2009 4:07:44 PM -> Syntax error in cfg file "LFSLapper.SC" at line #1775
Token not catched
Function 'printusergroup' script aborted
-----------------------------------------------------------------------------
9/13/2009 4:07:44 PM

Lapper Instance 67.240.186.71/12345 abort!

Stack empty.
mscorlib
at System.Collections.Stack.Pop()
at GLScript.GLApp.parseBackcall(SetOfVars GVAR, SetOfVars LVAR, unionVal val, ArrayList args)
at GLScript.Parseur.getval(SetOfVars GVAR, SetOfVars LVAR, executeParsedFunction BC)
at GLScript.GLApp.retrieveEvalVar(String funcName, TokenParse tkparse, TokenBuffer currTokenBuffer, SetOfVars GVAR, SetOfVars LVAR, Boolean breakFunc, Char& breakCar)
at GLScript.GLApp.privExecuteTokensPart(Int32 level, String funcName, SetOfVars GCAR, SetOfVars LVAR, Boolean breakable, Boolean inSwitchCase, Int32 start, Int32 end)
at GLScript.GLApp.privExecuteTokensPart(Int32 level, String funcName, SetOfVars GCAR, SetOfVars LVAR, Boolean breakable, Boolean inSwitchCase, Int32 start, Int32 end)
at GLScript.GLApp.executeTokensPart(String funcName, SetOfVars GVAR, SetOfVars LVAR, Int32 start, Int32 end)
at GLScript.GLApp.privExecuteFunction(String funcName, String[] argsVals)
at GLScript.GLApp.executeFunction(String funcName, String[] argsVals)
at Configurator.lexConfigurator.executeFunction(String funcName, infoPlayer pcurrInfoPlayer, String[] par)
at LFSLapper.LFSClient.managePacket(MSO mso)
at LFSLapper.LFSClient.Loop(Connect insimConnection)
at LFSLapper.LFSClient.doloop()
at LFSLapper.LFSListen.Listen.goWorkMode()
at LFSLapper.LFSListen.Listen.start()
System.Object Pop()
Closing Instance...
-----------------------------------------------------------------------------

(still crashes)
Quote from Fire_optikz001 :9/13/2009 4:07:44 PM -> Syntax error in cfg file "LFSLapper.SC" at line #1775
Token not catched
Function 'printusergroup' script aborted...

Can you cut & paste line 1775 from the LFSLapper.SC file as well as about 20 lines above and below it?
i made another addon for ur code (an update) thing like reload u can do !update (time)

<?php 
CASE "!update":
    IF( 
UserInGroup"tempadmin",$userName ) == )
        
THEN
     openGlobalButton
"lone_counter",50,63,100,40,100,$argv,0,"^3> %cpt% <"upda );

      
cmdLFS("/msg ^1INSIM UPDATE IN " $argv " SECOND(S) " );
      
cmdLFS("/msg ^2INSIM UPDATE IN " $argv " SECOND(S) " );
      
cmdLFS("/msg ^3INSIM UPDATE IN " $argv " SECOND(S) " );
      
cmdLFS("/msg ^4INSIM UPDATE IN " $argv " SECOND(S) " );
      
cmdLFS("/msg ^5INSIM UPDATE IN " $argv " SECOND(S) " );
      
cmdLFS("/msg ^6INSIM UPDATE IN " $argv " SECOND(S) " );
      
cmdLFS("/msg ^7INSIM UPDATE IN " $argv " SECOND(S) " );
      ELSE
              
privMsg"^1Access Denied");
    ENDIF
     BREAK;
?>


<?php 
Sub upda
($KeyFlags,$id)
   
SaveGroupToFile"tempadmin""./tempadmin.txt" );
 
update();
EndSub
?>



<?php 
Event OnDisConnect
() # Player event
   
RemoveUserFromGroup"tempadmin" GetCurrentPlayerVar("UserName"));
   
SaveGroupToFile"tempadmin""./tempadmin.txt" );

 
EndEvent
?>



<?php 
Event OnConnect
()
    
$userName GetCurrentPlayerVar("UserName");
            
UserGroupFromFile"loged""tempadmin.txt" );

                 IF( 
UserInGroup"loged",$userName ) == 1)
            
THEN
        privMsg
"^2Thank you for logging in");
        
MoveUserToGroup"tempadmin",$userName );
             ENDIF
EndEvent
?>


add the following to parseEvents.CS by termlapper

case "update":
TermProg = true;
RestartProg = true;
val.typVal = GLScript.typVal.str;
val.sval = quote("");
return;

I've updated the userGroup.cs file to do the listing in sorted order, so heres the whole file:
Attached files
userGroups.txt - 4.9 KB - 444 views
sry for bumping this topic

Lapper Crashed when i do !listgroup $argv

10/26/2009 7:05:40 PM
Lapper Instance 192.168.0.106/29999 abort!
De stack is leeg.
mscorlib
bij System.Collections.Stack.Pop()
bij GLScript.GLApp.parseBackcall(SetOfVars GVAR, SetOfVars LVAR, unionVal val, ArrayList args)
bij GLScript.Parseur.getval(SetOfVars GVAR, SetOfVars LVAR, executeParsedFunction BC)
bij GLScript.GLApp.retrieveEvalVar(String funcName, TokenParse tkparse, TokenBuffer currTokenBuffer, SetOfVars GVAR, SetOfVars LVAR, Boolean breakFunc, Char& breakCar)
bij GLScript.GLApp.privExecuteTokensPart(Int32 level, String funcName, SetOfVars GCAR, SetOfVars LVAR, Boolean breakable, Boolean inSwitchCase, Int32 start, Int32 end)
bij GLScript.GLApp.privExecuteTokensPart(Int32 level, String funcName, SetOfVars GCAR, SetOfVars LVAR, Boolean breakable, Boolean inSwitchCase, Int32 start, Int32 end)
bij GLScript.GLApp.privExecuteTokensPart(Int32 level, String funcName, SetOfVars GCAR, SetOfVars LVAR, Boolean breakable, Boolean inSwitchCase, Int32 start, Int32 end)
bij GLScript.GLApp.privExecuteTokensPart(Int32 level, String funcName, SetOfVars GCAR, SetOfVars LVAR, Boolean breakable, Boolean inSwitchCase, Int32 start, Int32 end)
bij GLScript.GLApp.executeTokensPart(String funcName, SetOfVars GVAR, SetOfVars LVAR, Int32 start, Int32 end)
bij GLScript.GLApp.privExecuteFunction(String funcName, String[] argsVals)
bij GLScript.GLApp.executeFunction(String funcName, String[] argsVals)
bij Configurator.lexConfigurator.executeFunction(String funcName, infoPlayer pcurrInfoPlayer, String[] par)
bij LFSLapper.LFSClient.managePacket(MSO mso)
bij LFSLapper.LFSClient.Loop(Connect insimConnection)
bij LFSLapper.LFSClient.doloop()
bij LFSLapper.LFSListen.Listen.goWorkMode()
bij LFSLapper.LFSListen.Listen.startStbMode()
System.Object Pop()
Closing Instance...


I have add the last userGroups.cs and the codes that Krayy send before
From what i recall, FireOptiks had the same problem and we found that the parameter "$username" in the !listgroup command had a different case in his lapper file and was actullay "$UserName". Check yours and see if thats the same.
Quote from Krayy :From what i recall, FireOptiks had the same problem and we found that the parameter "$username" in the !listgroup command had a different case in his lapper file and was actullay "$UserName". Check yours and see if thats the same.

nope its not the problem it wont work at all
i have change it back to $userName
see code below



CASE "!listgroup":
IF( UserInGroup( "UserAdmin",$userName ) == 1 )
THEN
IF( $argv != "" ) THEN
privMsg( "^3Current members of group: " . $argv . "^8" );
PrintUserGroup ($argv);
ELSE
privMsg( "^3You must specify a user group to list^8" );
ENDIF
ENDIF
BREAK;


Sub PrintUserGroup ($UserGroup)
$IsNotBlank = 1;
$GroupIndex = 0;
WHILE ($IsNotBlank == 1)
$GroupUser=split( ListGroupUsers($UserGroup),",",$GroupIndex );
IF ( $GroupUser != "") THEN
privmsg($GroupUser);
$GroupIndex = $GroupIndex + 1;
ELSE
$IsNotBlank = 0;
ENDIF
ENDWHILE
EndSub

krayy i really need ur help now
Found the problem....at the end of the line that says EndSub of the PrintUserGroup function, you have got some extra control characters that are breaking the script. You cannot see them normally, so if you position the cursor at the end of the word EndSub, use Shift+Down arrow to select the end of that line and a couple of blank lines below it and delete them then it runs ok.

Make sure that you are using a text editor that can save the file in a plain text format like Notepad+++ or PSPad Editor.

Also, you can call the !listgroup function (i change it to !lg) using:
!listgroup UserAdmin
thx krayy it works now
weird bug but it works

when u do !listgroup blablabla
then it shows the users in grey color
can i change this color??
1

FGED GREDG RDFGDR GSFDG