Source-Python-Dev-Team / Source.Python

This plugin aims to use boost::python and create an easily accessible wrapper around the Source Engine API for scripter use.
http://forums.sourcepython.com
GNU General Public License v3.0
163 stars 31 forks source link

ConCommandBase identifies sv_pure and log as commands, not cvars #339

Closed p-hennessy closed 4 years ago

p-hennessy commented 4 years ago

Operating System: Ubuntu 18.04.4 LTS Game: Team Fortress 2, Server Version 5932704

SP Version: ``` -------------------------------------------------------- Checksum : 51f107e6aa2065b2e4eea2cbc5534bdb Date : 2020-06-20 19:24:51.592387 OS : Linux-5.3.0-1023-aws-x86_64-with-debian-buster-sid Game : tf2 SP version : 696 Github commit : 268d1d7b1a46946133bc6df5ccf46687a718917c Server plugins: 00: Metamod:Source 1.10.7-dev 01: Source.Python, (C) 2012-2020, Source.Python Team. SP plugins: 00: logger, 1.0.0, https://github.com/scrims-tf/sourcepython-plugins/tree/master/logger 01: gamemodes, 1.0.1, https://github.com/scrims-tf/sourcepython-plugins/tree/master/gamemodes 02: reservation, 1.0.0, https://github.com/scrims-tf/sourcepython-plugins/tree/master/reservation 03: admin, 1.1.0, https://github.com/scrims-tf/sourcepython-plugins/tree/master/admin 04: connect, 1.0.0, https://github.com/scrims-tf/sourcepython-plugins/tree/master/connect 05: logstf_discord, 1.0.0, https://github.com/scrims-tf/sourcepython-plugins/tree/master/logstf_discord 06: sp_exec -------------------------------------------------------- ```

Simplified version of the problem i'm seeing:

from cvars import cvar

base = cvar.find_base("sv_pure")
print(base.is_command()) # returns True when it should return False

sv_pure ( at least in TF2 ) is definatly a cvar and this is being returned as a command. log is also having the same behavior. I suspect there are a few other cvars being incorrectly flagged as commands.

Is this a sourcesdk issue or an sp one? I can hardcode around it but wondering if this is a larger issue worth looking at.

Edit: Found another, tv_msg

Ayuto commented 4 years ago

No, it's working correctly. sv_pure is a server command. This can be seen by the output if you enter them in the server console. Usually, ConVars looks like this (name, value, flags, help text). This is a unified output:

sv_cheats
"sv_cheats" = "0"
 notify replicated
 - Allow cheats on server

While the output of sv_pure looks like this (custom output):

sv_pure
--------------------------------------------------------
sv_pure: Only allow client to use certain files.

  -1 - Do not apply any rules or restrict which files the client may load.
   0 - Apply rules in cfg/pure_server_minimal.txt only.
   1 - Apply rules in cfg/pure_server_full.txt and then cfg/pure_server_whitelist.txt.
   2 - Apply rules in cfg/pure_server_full.txt.

   See cfg/pure_server_whitelist_example.txt for more details.

Current sv_pure value is 0.
--------------------------------------------------------

Wether or not is_command returns True is determined by their class. Basically, it's implemented like this:

# abstract class
class ConCommandBase(object):
    def __init__(self, name):
        self.name = name

    def is_command(self):
        raise NotImplementedError

class ConVar(ConCommandBase):
    def is_command(self):
        return False

class ConCommand(ConCommandBase):
    def is_command(self):
        return True

sv_pure = ConCommand('sv_pure')
print(sv_pure.is_command()) # Returns True

sv_cheats = ConVar('sv_cheats')
print(sv_cheats.is_command()) # Returns False

So, it's very unlikely that you get a false result, because there are no flags that could be changed or interpreted incorrectly.

Ayuto commented 4 years ago

cvarlist also says it's a server command:

cvarlist sv_pure
cvar list
--------------
sv_pure                                  : cmd      :                  : Show user data.
sv_pure_consensus                        : 5        :                  : Minimum number of file hashes to agree to form a consensus.
sv_pure_kick_clients                     : 1        :                  : If set to 1, the server will kick clients with mismatching files. Otherwise, it will issue a warning to the client.
sv_pure_retiretime                       : 900      :                  : Seconds of server idle time to flush the sv_pure file hash cache.
sv_pure_trace                            : 0        :                  : If set to 1, the server will print a message whenever a client is verifying a CRC for a file.
--------------
  5 convars/concommands for [sv_pure]
p-hennessy commented 4 years ago

Interesting. Thanks for the explaination!

I am able to set the value for sv_pure using the ConVar api but it doesnt apply to the actual game so that makes sense.