[CS:GO] Print console admin log

Please post any questions about developing your plugin here. Please use the search function before posting!
cssbestrpg
Senior Member
Posts: 287
Joined: Sun May 17, 2020 7:56 am
Location: Finland
Contact:

[CS:GO] Print console admin log

Postby cssbestrpg » Thu Mar 25, 2021 9:38 am

Hi, guys i have issue with make print admin log to console. It keep giving this error:

Code: Select all

[SP] Caught an Exception:
Traceback (most recent call last):
  File "..\addons\source-python\packages\source-python\commands\auth.py", line 44, in __call__
    return self.callback(*args)
  File "..\addons\source-python\packages\source-python\menus\queue.py", line 267, in _menuselect_callback
    _radio_queues[index]._select(choice)
  File "..\addons\source-python\packages\source-python\menus\queue.py", line 126, in _select
    next_menu = active_menu._select(self._index, choice)
  File "..\addons\source-python\packages\source-python\menus\radio.py", line 113, in _select
    self._player_pages[player_index].options[choice_index])
  File "..\addons\source-python\packages\source-python\menus\base.py", line 126, in _select
    return self.select_callback(self, player_index, choice_index)
  File "..\addons\source-python\plugins\rpg\modules\admin\__init__.py", line 749, in log_choice_menu_callback
    f = open(_logs.joinpath(steamid), 'r', encoding="utf8")

AttributeError: 'str' object has no attribute 'joinpath'


In linux this code works fine, but at windows it have issue

Syntax: Select all

def log_choice_menu_callback(_menu, _index, _option):
choice = _option.value
if choice:
userid = rpglib.useridFromIndex(_index)
if rpg.SOUND_SELECT:
rpglib.playgamesound(userid, rpg.SOUND_SELECT)
if choice == 'view':
steamid = rpg.players[userid]['log']
f = open(_logs.joinpath(steamid), 'r', encoding="utf8")
console_message(userid, ' ')
console_message(userid, '******************* LOG START *******************')
console_message(userid, ' ')
for i in f.readlines():
console_message(userid, '%s' % (i.replace('\n', '').replace('\r', '')))
f.close()
console_message(userid, ' ')
console_message(userid, '******************* LOG END *******************')
rpglib.tell(userid, '\x04Log %s has been printed to your console' % (steamid))
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: [CS:GO] Print console admin log

Postby satoon101 » Thu Mar 25, 2021 12:44 pm

Where is _logs defined and what is it defined as?
Image
cssbestrpg
Senior Member
Posts: 287
Joined: Sun May 17, 2020 7:56 am
Location: Finland
Contact:

Re: [CS:GO] Print console admin log

Postby cssbestrpg » Thu Mar 25, 2021 12:49 pm

The _logs is defined as:

Syntax: Select all

_logs = os.path.join(__FILEPATH__ + '/logs/')
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: [CS:GO] Print console admin log

Postby satoon101 » Thu Mar 25, 2021 12:58 pm

I'm not sure how that works on Linux. The value of that, regardless of operating system, will be a str. And str objects don't have a joinpath method.

I would highly recommend using the path package, much like we have in the paths module:
https://github.com/Source-Python-Dev-Te ... n/paths.py

instead of using os.path natively.
Image
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: [CS:GO] Print console admin log

Postby satoon101 » Thu Mar 25, 2021 1:10 pm

Also, there's already a default location for SP logs, so why not create a directory in there to store everything of that sort in 1 location:
https://github.com/Source-Python-Dev-Te ... ths.py#L88

Syntax: Select all

from paths import LOG_PATH
_logs = LOG_PATH / 'rpg'

...

console_message(userid, ' ')
console_message(userid, '******************* LOG START *******************')
console_message(userid, ' ')
player_log = _logs / steamid
with player_log.open('r', encoding='utf8') as f:
for i in f.readlines():
console_message(userid, '%s' % (i.replace('\n', '').replace('\r', '')))
Image
cssbestrpg
Senior Member
Posts: 287
Joined: Sun May 17, 2020 7:56 am
Location: Finland
Contact:

Re: [CS:GO] Print console admin log

Postby cssbestrpg » Thu Mar 25, 2021 2:48 pm

Thanks for answer, i got it work

Return to “Plugin Development Support”

Who is online

Users browsing this forum: Bing [Bot] and 27 guests