Author Topic: [ADDON] Private Race Access  (Read 3666 times)

Remy Lebeau

  • Sr. Member
  • ****
  • Posts: 497
    • View Profile
[ADDON] Private Race Access
« on: December 22, 2012, 03:39:22 AM »
On our server we create and give people private races.  I've created a little addon that manages this system, so that it can easily be updated through a .cfg file (Thanks to Necavi for a major overhaul) - This plugin also creates pretty blue rings around players who spawn on a private race.

INSTALLATION

* Compile the .sp, include in your usual plugins location.
* Modify the .cfg to suit your needs (instructions are in the file itself).  It needs to be located in sourcemod/configs

IN GAME USAGE

Commands
- war3_reload_private_races: reloads the .cfg file
- war3_add_player_to_race <race short name> <player steam ID> <player name>
- war3_remove_player_from_race <race short name> <player steam ID>

Cvars
- war3_private_race_min_players: Disallows players from selecting private races when the server has fewer than this many players (default 2)

Note: All commands require the RCON flag


CHANGELOG:

v1
- OLD system that just force changed onto undead

v2
- updated to use deny events to not allow the player to change at all

v3.0.0
- re-written by necavi to include admin commands to manage the plugin, as well as reducing the amount it loads from the config file

v3.0.1
- bugfix, removed a false file load warning.
- changed the plugin URL to war3source.com - multiple authors means we might as well bring the credit back to here.
« Last Edit: December 27, 2012, 09:56:34 PM by Remy Lebeau »

Ownz

  • Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 2437
  • chmod -R 777 *
    • View Profile
    • OwnageClan
Re: [ADDON] Private Race Access
« Reply #1 on: December 22, 2012, 09:41:02 AM »
so every race needs an entry?

I think the easier way is to have 1 single steamid and it list all the races following it

Remy Lebeau

  • Sr. Member
  • ****
  • Posts: 497
    • View Profile
Re: [ADDON] Private Race Access
« Reply #2 on: December 22, 2012, 03:07:46 PM »
Only the races that you want to be private need an entry.  It works quite well this way, since you can see at a glance who has access to which race.

The things is that most of the time people DON'T have access to multiple private races (since they are private), but you might have 4 or 5 people with access to one private race.  So I think it works best as it is.

Again, races that are not private don't need an entry in this .cfg


Revan

  • Hero Member
  • *****
  • Posts: 513
    • View Profile
Re: [ADDON] Private Race Access
« Reply #3 on: December 22, 2012, 05:58:11 PM »
That's cool, I always wanted such a thing. Now I can trash my ueber long w3cvar with tons of steamid's :D
#war3source on gamesurge

Necavi

  • Sr. Member
  • ****
  • Posts: 499
    • View Profile
Re: [ADDON] Private Race Access
« Reply #4 on: December 26, 2012, 04:46:17 AM »
I took the liberty of nearly completely rewriting this plugin, here is a (rough) list of changes:
- No longer reads the keyvalue from disk each time someone attempts to change race (slow even with FEW players in the kv, let alone a LOT)
- Added command war3_reload_private_races: reloads and parses the private race keyvalue
- Added command war3_add_player_to_race: Adds a player to a race's permission system - will add the race's key if it doesn't exist yet.
- Added command war3_remove_player_from_race: Removes a player from a race's permission system - will remove the race's key if it is the last permission node left (keep a dummy key such as STEAM_PRIVATE around if you don't want this)
- Added Convar war3_private_race_min_players: Disallows players from selecting private races when the server has fewer than this many players
- Modified restrict message to read the war3_clanurl cvar instead of being hard coded to your community's name
- Renamed a few variables
- Made the is private race variable reset on player connect (to avoid the possibility of extra messages)
- Renamed the config to war3source_privateraces.cfg
- Made comparisons use raceID's instead of race short names (greatly speeding everything up even more)
Note: All commands require the RCON flag
Note: the add/remove commands both reload the config first (to prevent issues).

Overall quite a bit more powerful and generally a more useful plugin, hope you enjoy!
(Partially rewrote because I was playing on your server a bit and this system didn't seem up to par)
« Last Edit: December 26, 2012, 06:25:43 AM by Necavi »

Remy Lebeau

  • Sr. Member
  • ****
  • Posts: 497
    • View Profile
Re: [ADDON] Private Race Access
« Reply #5 on: December 27, 2012, 02:29:50 PM »
Good work :-)

This was my very first attempt at parsing a cfg file, so I'm more than happy with how you've updated it.  I guess to allow proper customisation it should also include a cvar to enable/disable the blue rings when you spawn on a custom race.

Remy Lebeau

  • Sr. Member
  • ****
  • Posts: 497
    • View Profile
Re: [ADDON] Private Race Access
« Reply #6 on: December 27, 2012, 09:40:41 PM »
Update OP with Necavi's version + bugfix.

Jumpman

  • Full Member
  • ***
  • Posts: 123
    • View Profile
Re: [ADDON] Private Race Access
« Reply #7 on: April 24, 2016, 09:10:35 AM »
I have full rcon (z) on my server but something not working all the files are in the right folders, i have not write anything in war3source_privateraces.cfg that i assume it writes to the file itself but anyway this command below not working ?

war3_add_player_to_race 28 STEAM_0:1:437xxx Jumpman
Unknown command: war3_add_player_to_race
[+35]Jumpman

abgar

  • Full Member
  • ***
  • Posts: 114
    • View Profile
Re: [ADDON] Private Race Access
« Reply #8 on: May 02, 2016, 10:47:22 PM »
The correct syntax to use is:
sm_add_player_to_race <race short name> <player steam ID> <player name>

i.e:
sm_add_player_to_race undead STEAM_0:1:437xxx Jumpman

Using the race NUMBER, (28) won't work unless you have a race with the short name of "28"

Jumpman

  • Full Member
  • ***
  • Posts: 123
    • View Profile
Re: [ADDON] Private Race Access
« Reply #9 on: May 03, 2016, 02:10:47 AM »
Ok thanks again

After compiling War3Source_Addon_PrivateRaces.sp i get this warning

War3Source_Addon_PrivateRaces.sp(202) : warning 234: symbol "GetClientAuthString" is marked as deprecated: Use GetClientAuthId

From another topic in alliedmods i have the same problem with another .sp file and they tell me i can use Sourcemod 1.6.3 to compile this plugin, but why not change it to work with sourcemod 1.7 so i dont need to have multiple versions of sourcemod lying can you help me with this one to abgar ?
[+35]Jumpman

abgar

  • Full Member
  • ***
  • Posts: 114
    • View Profile
Re: [ADDON] Private Race Access
« Reply #10 on: May 03, 2016, 03:08:07 AM »
Well the warning tell you everything you need to know there :)

Just change GetClientAuthString to GetClientAuthID :)

Think of it as the new version of GetClientAuthString - it was changed to align with the changes to string definitions that Sourcemod will hopefully be implementing in the future.

Warnings like this won't actually impact playability either, it's just telling you that a future version of Sourcemod won't support GetClientAuthString anymore - so prepare for that :)

Jumpman

  • Full Member
  • ***
  • Posts: 123
    • View Profile
Re: [ADDON] Private Race Access
« Reply #11 on: May 03, 2016, 03:52:59 AM »
Yes i allready try that then i get 2 errors if i change GetClientAuthString out with GetClientAuthId

War3Source_Addon_PrivateRaces.sp(202) : error 035: argument type mismatch (argument 2)
War3Source_Addon_PrivateRaces.sp(202) : error 035: argument type mismatch (argument 3)
[+35]Jumpman

abgar

  • Full Member
  • ***
  • Posts: 114
    • View Profile
Re: [ADDON] Private Race Access
« Reply #12 on: May 03, 2016, 04:00:55 AM »
Oh yeah, different syntax.

Well there's an example of GetClientAuthId in the HUD on this forum, or as i said, you can actually just leave it, too.  It still compiles fine, and will continue to work.

Jumpman

  • Full Member
  • ***
  • Posts: 123
    • View Profile
Re: [ADDON] Private Race Access
« Reply #13 on: May 03, 2016, 04:22:35 AM »
Ok look like it work i just need to know if this is right compile without errors and warnings :-)

Change line 201 and 202
Code: [Select]
new String:auth[32];
GetClientAuthString(client, auth, sizeof(auth));
to
Code: [Select]
new String:auth[128];
    GetClientAuthId(client, AuthId_Steam2, auth, sizeof(auth));
[+35]Jumpman

abgar

  • Full Member
  • ***
  • Posts: 114
    • View Profile
Re: [ADDON] Private Race Access
« Reply #14 on: May 03, 2016, 06:14:50 AM »
Looks good - test it and confirm :)

Jumpman

  • Full Member
  • ***
  • Posts: 123
    • View Profile
Re: [ADDON] Private Race Access
« Reply #15 on: May 03, 2016, 07:50:41 AM »
Aw have problem

L 05/03/2016 - 15:34:46: [SM] Native "GetConVarString" reported: Invalid convar handle 0 (error 4)
L 05/03/2016 - 15:34:46: [SM] Displaying call stack trace for plugin "w3s/War3Source_Addon_PrivateRaces.smx":
L 05/03/2016 - 15:34:46: [SM]   
  •   Line 43, War3Source_Addon_PrivateRaces.sp::OnPluginStart()


Line 34 to 46 look like this
Code: [Select]
public OnPluginStart()
{
HookEvent("round_start",RoundStartEvent);
RegAdminCmd("war3_reload_private_races",Command_Reload, ADMFLAG_RCON,"Reloads the private race access file");
RegAdminCmd("war3_add_player_to_race", Command_AddPlayer, ADMFLAG_RCON, "Adds a player to a restricted race.");
RegAdminCmd("war3_remove_player_from_race", Command_RemovePlayer, ADMFLAG_RCON, "Removes a player from a restricted race.");
new Handle:cvarReqPlayers = CreateConVar("war3_private_race_min_players","2", "The minimum number of players required to use private races",0, true, 0.0, true, float(MaxClients));
HookConVarChange(cvarReqPlayers, ConVar_ReqPlayers);
new Handle:cvarClanUrl = FindConVar("war3_clanurl");
GetConVarString(cvarClanUrl, g_sServerUrl, sizeof(g_sServerUrl));
HookConVarChange(cvarClanUrl, ConVar_ClanUrl);
ReloadConfig();
}
« Last Edit: May 03, 2016, 07:52:20 AM by Jumpman »
[+35]Jumpman

abgar

  • Full Member
  • ***
  • Posts: 114
    • View Profile
Re: [ADDON] Private Race Access
« Reply #16 on: May 03, 2016, 09:53:07 PM »
Well im no expert on CVARs by any means, but it looks as though for some reason the PrivateRaces plugins is being loaded before the war3_clanurl is created, hence it saying there's an error. 

If you wanted to, you could remove the need for that completely - it's actually only used in the Print message:
CPrintToChat( client, "{red}Access: - DENIED - {default}Get your own private race at %s!", g_sServerUrl);   

You could just remove the CVAR completely, and then change the message (row 208) to hard write your server URL, or something like:
CPrintToChat( client, "{red}Access: - DENIED - {default}Get your own private race by contacting a server Admin");

OR, you could just leave the error - as it shouldn't actually be impacting functionality or performance.  The only thing i'd suggest is in it's current state, try setting a race so you DON"T have access to it, and then try and change to that race.  See what Chat message populates. 

Jumpman

  • Full Member
  • ***
  • Posts: 123
    • View Profile
Re: [ADDON] Private Race Access
« Reply #17 on: May 04, 2016, 12:18:25 PM »
Hope i did it right, i remove

new Handle:cvarClanUrl = FindConVar("war3_clanurl");
GetConVarString(cvarClanUrl, g_sServerUrl, sizeof(g_sServerUrl));
HookConVarChange(cvarClanUrl, ConVar_ClanUrl);

and change

CPrintToChat( client, "{red}Access: - DENIED - {default}Get your own private race at %s!", g_sServerUrl);
to
CPrintToChat( client, "{red}Access: - DENIED - {default}Get your own private race by contacting a server Admin");

Now it compile without errors hope it was the right thing i change and removed ?

[+35]Jumpman

abgar

  • Full Member
  • ***
  • Posts: 114
    • View Profile
Re: [ADDON] Private Race Access
« Reply #18 on: May 04, 2016, 11:04:24 PM »
Yep - that looks right.  But again, test and confirm

Jumpman

  • Full Member
  • ***
  • Posts: 123
    • View Profile
Re: [ADDON] Private Race Access
« Reply #19 on: May 06, 2016, 04:16:38 PM »
Test it not working

sm_add_player_to_race undead U:1:87xxxx Jumpman
war3_add_player_to_race undead U:1:87xxxx Jumpman
Unknown command: sm_add_player_to_race

Jumpman :  changerace (not working right now)
Jumpman :  wcs (not working right now war3menu do not come up)
failed to load private race config file

Hmm this file is in my addons\sourcemod\configs\war3source_privateraces.cfg
« Last Edit: May 06, 2016, 04:25:21 PM by Jumpman »
[+35]Jumpman

Revan

  • Hero Member
  • *****
  • Posts: 513
    • View Profile
Re: [ADDON] Private Race Access
« Reply #20 on: May 06, 2016, 05:16:46 PM »
Post your error logs, if changerace doesn't work the logs probably have more information about why.

What's the content of addons\sourcemod\configs\war3source_privateraces.cfg?

What's the message you get when you run "war3_reload_private_races" from your console?
#war3source on gamesurge

Jumpman

  • Full Member
  • ***
  • Posts: 123
    • View Profile
Re: [ADDON] Private Race Access
« Reply #21 on: May 09, 2016, 02:41:59 AM »
changerace works again i think have something to do that i have 4 races not working but they work now so not have any problems anymore with changerace

war3source_privateraces.cfg
Code: [Select]
// "Race Access" <-- Leave this alone
// { <-- Add all groups/steamids after first bracket (Leave this alone)
//
// "lara" <-- add each race by it's shortname.  capitalization shouldn't matter, but better match just to be sure
// {
// "STEAM_0:1:1234567" "Jumpman" <-- Enter the STEAM ID for each player who is authorized.  The name doesn't matter - it's just to make it easier to change
// "STEAM_0:1:98765332" "Hugo" <-- This is the color of the text
// }
//
// "phantom"
// {
// "STEAM_0:1:1234567" "Jumpman" <-- You can have a single person with access to any number of races
// "STEAM_0:1:43654854" "Bent"
// }
// } <-- Add all groups/steamids before last bracket (Leave this alone)


"Private Races"
{
"racename1"
{
"STEAM_0:1:1234567" "Test"
"STEAM_0:1:98765332" "Hugo"
}

"racename1"
{
"STEAM_0:1:1234567" "Test"
"STEAM_0:1:43654854" "Bent"
}
}

Running war3_reload_private_races i get this

Unable to reload config! Please check the formatting.

I use notapad++ encoding in UTF-8 without BOM

Do i need to chmod war3source_privateraces.cfg right now it's 644
[+35]Jumpman

Jumpman

  • Full Member
  • ***
  • Posts: 123
    • View Profile
Re: [ADDON] Private Race Access
« Reply #22 on: May 10, 2016, 12:04:35 PM »
I have change line 202 and 203 want to use new steamid hope thats right what im done ?

Code: [Select]
new String:auth[128];
    GetClientAuthId(client, AuthId_Steam3, auth, sizeof(auth));

The script i downloaded and want to use is yours Revan 3.0.1 first post

Error in log says:
Code: [Select]
L 05/10/2016 - 19:45:27: SourceMod error session started
L 05/10/2016 - 19:45:27: Info (map "de_dust2") (file "errors_20160510.log")
L 05/10/2016 - 19:45:27: [SM] Native "GetConVarString" reported: Invalid convar handle 0 (error 4)
L 05/10/2016 - 19:45:27: [SM] Displaying call stack trace for plugin "w3s/War3Source_Addon_PrivateRaces.smx":
L 05/10/2016 - 19:45:27: [SM]   [0]  Line 43, War3Source_Addon_PrivateRaces.sp::OnPluginStart()

Command i use is
rcon war3_add_player_to_race undead U.1:874251 Jumpman (new steamid)

Nothing happens when i write war3_reload_private_races nothing happens when i write rcon war3_add_player_to_race undead U.1:874251 Jumpman

Problem was i forget to use rcon before command i not get any warnings in console when use command now

I look in configs/war3source_privateraces.cfg not add any thing to this file after i use command rcon war3_add_player_to_race undead U.1:874251 Jumpman
Code: [Select]
"Private Races"
{
"undead"
{
"STEAM_0:1:1234567" "Test"
"STEAM_0:1:98765332" "Hugo"
}

"racename1"
{
"STEAM_0:1:1234567" "Test"
"STEAM_0:1:43654854" "Bent"
}
}

Is it not possible to rewrite plugin so it convert new steamid to old steamid in war3source_privateraces.cfg like we do in HLstatsX:CE --> https://forums.alliedmods.net/showthread.php?t=246712

When write status in console you get the new steamid but when i look in mysql database war3source table i stand with the old steamid ?
« Last Edit: May 10, 2016, 12:25:16 PM by Jumpman »
[+35]Jumpman

Jumpman

  • Full Member
  • ***
  • Posts: 123
    • View Profile
Re: [ADDON] Private Race Access
« Reply #23 on: May 12, 2016, 01:44:30 AM »
There is something wrong not work for me :-(

sm_add_player_to_race undead U:1:874251 Jumpman
Unknown command: sm_add_player_to_race

war3_add_player_to_race undead U:1:874251 Jumpman
Unknown command: war3_add_player_to_race
Insufficient parameters: sm_add_player_to_race <race short name> <player steam ID> <player name>

sm_add_player_to_race undead U:1:874251 Jumpman
Unknown command: sm_add_player_to_race

rcon sm_add_player_to_race undead U:1:874251 Jumpman
Unknown command "sm_add_player_to_race"

rcon war3_add_player_to_race undead U:1:874251 Jumpman
Insufficient parameters: sm_add_player_to_race <race short name> <player steam ID> <player name>

rcon sm_add_player_to_race undead STEAM_0:1:437125 Jumpman
Unknown command "sm_add_player_to_race"

war3_reload_private_races
Unable to reload config! Please check the formatting.

rcon war3_reload_private_races
Unable to reload config! Please check the formatting.
[+35]Jumpman

Jumpman

  • Full Member
  • ***
  • Posts: 123
    • View Profile
Re: [ADDON] Private Race Access
« Reply #24 on: May 16, 2016, 06:43:13 AM »
What im doing wrong here, why cant i get it to work ?
[+35]Jumpman