View Full Version : [CODE] List and Save Usergroups (particularly the admin group)
Krayy
11th September 2009, 10:41
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:
CASE "!listgroup":
IF( UserInGroup( "admin",$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;
CASE "!admins":
IF( UserInGroup( "admin",$userName ) == 1 )
THEN
IF( $argv != "" ) THEN
$idxSpace = indexOf( $argv, " ");
IF( $idxSpace != -1 ) THEN
$option = subStr( $argv,0,$idxSpace );
$argv = trim( subStr( $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:
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
Happy racing.
Tim NL
11th September 2009, 10:59
:thumb::thumb::thumb::thumb: Thanks.
Bass-Driver
11th September 2009, 15:06
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;
Krayy
11th September 2009, 22:10
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
Bass-Driver
11th September 2009, 22:43
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>
Krayy
12th September 2009, 05:21
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.
Bass-Driver
12th September 2009, 08:57
k got it
when i want to debug it said
the working directory does not exist
D\Dev\Devinsim\lapper\LFSLapper\LFSLapperBin\Relea se\'.
is it possible to send your LFSLapper.exe to me via my email.
thx
Krayy
12th September 2009, 10:34
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.
Bass-Driver
12th September 2009, 11:31
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.
Fire_optikz001
12th September 2009, 16:15
lol i have mine locked up so tight u have to be a admin or a beta tester to do the !login command itself
Krayy
12th September 2009, 22:04
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?
Fire_optikz001
12th September 2009, 23:50
Nvm
Fire_optikz001
13th September 2009, 03:29
9/12/2009 9:27:00 PM -> Syntax error in cfg file "LFSLapper.lpr" at line #1745
Token not catched
Function 'printusergroup' script aborted
Bass-Driver
13th September 2009, 17:56
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)
Krayy
13th September 2009, 22:02
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.
Fire_optikz001
13th September 2009, 22:06
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(Strin g 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)
Krayy
13th September 2009, 22:34
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?
Fire_optikz001
13th September 2009, 23:21
i made another addon for ur code (an update) thing like reload u can do !update (time) :D
CASE "!update":
IF( UserInGroup( "tempadmin",$userName ) == 1 )
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;
Sub upda($KeyFlags,$id)
SaveGroupToFile( "tempadmin", "./tempadmin.txt" );
update();
EndSub
Event OnDisConnect() # Player event
RemoveUserFromGroup( "tempadmin" , GetCurrentPlayerVar("UserName"));
SaveGroupToFile( "tempadmin", "./tempadmin.txt" );
EndEvent
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;
Krayy
20th September 2009, 04:38
I've updated the userGroup.cs file to do the listing in sorted order, so heres the whole file:
Bass-Driver
26th October 2009, 18:16
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(Strin g 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
Krayy
27th October 2009, 01:21
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.
Bass-Driver
27th October 2009, 16:37
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
Bass-Driver
31st October 2009, 10:17
krayy i really need ur help now
Krayy
2nd November 2009, 21:34
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
Bass-Driver
3rd November 2009, 11:24
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??
Krayy
3rd November 2009, 19:37
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??
Just add colour code where it does the privMsg in the PrintUserGroup Sub as thats the output like this:
IF ( $GroupUser != "") THEN
privMsg ("^3" . $GroupUser . "^8");
$GroupIndex = $GroupIndex + 1;
ELSE
Bass-Driver
3rd November 2009, 19:50
k thx
rattijonni1
8th May 2010, 13:48
how this insim working??
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.