Skip to content

Commit

Permalink
Merge pull request #64 from Fluffy41/main
Browse files Browse the repository at this point in the history
feat: Add SCP: Secret Laboratory protocol support
  • Loading branch information
BattlefieldDuck committed Jan 21, 2024
2 parents 895a723 + e70172e commit 17dd69b
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions discordgsm/games.csv
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ rust,Rust (2018),source,port=28015

samp,San Andreas Multiplayer (2006),samp,port=7777
satisfactory,Satisfactory (2019),satisfactory,port_query=15777
scpsl,SCP: Secret Laboratory (2017),scpsl
scum,SCUM (2018),scum,port=27015
shatteredhorizon,Shattered Horizon (2009),source,port=27015
ship,The Ship (2006),source,port=27015
Expand Down
8 changes: 8 additions & 0 deletions discordgsm/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,14 @@ def query_server_modal(game: GamedigGame, locale: Locale):
if game['id'] == 'terraria':
query_extra['_token'] = TextInput(label='REST user token')
modal.add_item(query_extra['_token'])
elif game['id'] == 'scpsl':
query_extra['_servername'] = TextInput(label='Server name')
query_extra['_token'] = TextInput(label='API Key')
query_extra['_accountid'] = TextInput(label='Account ID')
modal.add_item(query_extra['_token']).add_item(query_extra['_accountid']).add_item(query_extra['_servername'])
modal.remove_item(query_param['port']).remove_item(query_param['host'])
query_param['port']._value = '0'
query_param['host']._value = 'api.scpslgame.com'
elif game['id'] == 'gportal':
query_extra['serverId'] = TextInput(label='GPORTAL server id')
modal.add_item(query_extra['serverId'])
Expand Down
1 change: 1 addition & 0 deletions discordgsm/protocols/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from .raknet import Raknet
from .samp import Samp
from .satisfactory import Satisfactory
from .scpsl import SCP_SL
from .scum import Scum
from .source import Source
from .teamspeak3 import Teamspeak3
Expand Down
42 changes: 42 additions & 0 deletions discordgsm/protocols/scpsl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import time
from typing import TYPE_CHECKING

import aiohttp

from discordgsm.protocols.protocol import Protocol

if TYPE_CHECKING:
from discordgsm.gamedig import GamedigResult

class SCP_SL(Protocol):
name = 'scp_sl'

async def query(self):
token, accountid, servername = str(self.kv['_token']), str(self.kv['_accountid']), str(self.kv['_servername'])

url = f'https://api.scpslgame.com/serverinfo.php?id={accountid}&key={token}&lo=true&players=true&list=true&version=true&flags=true&online=true'

start = time.time()

async with aiohttp.ClientSession() as session:
async with session.get(url) as response:
data = await response.json()

server_info = data.get("Servers", [])[0] if data.get("Servers") else {}
ping = int((time.time() - time.mktime(time.strptime(server_info.get('LastOnline', '1970-01-01'), "%Y-%m-%d"))) * 1000)

result: GamedigResult = {
'name': f'{servername} - SCP SL Server {server_info.get("ID", "Offline")}',
'map': '',
'password': False,
'numplayers': int(server_info.get("Players", "0/0").split("/")[0]),
'numbots': 0,
'maxplayers': int(server_info.get("Players", "0/0").split("/")[1]),
'players': [{'name': player, 'raw': player} for player in server_info.get('PlayersList', [])],
'bots': None,
'connect': None,
'ping': ping,
'raw': data
}

return result

0 comments on commit 17dd69b

Please sign in to comment.