mirror of
https://codeberg.org/spire/sdrconnect.git
synced 2026-06-03 06:14:09 +02:00
initial version
This commit is contained in:
commit
62099bdba0
9 changed files with 276 additions and 0 deletions
1
.envrc
Normal file
1
.envrc
Normal file
|
|
@ -0,0 +1 @@
|
|||
use flake
|
||||
27
.github/workflows/compile.yml
vendored
Normal file
27
.github/workflows/compile.yml
vendored
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
name: Build sourcepawn and commit
|
||||
|
||||
on:
|
||||
push:
|
||||
paths:
|
||||
- '**.sp'
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Compile sourcepawn
|
||||
uses: spiretf/spcomp@v0.1
|
||||
with:
|
||||
source: './plugin/sdrconnect.sp'
|
||||
target: './plugin/sdrconnect.smx'
|
||||
|
||||
- name: Commit files
|
||||
run: |
|
||||
git config --local user.email "action@github.com"
|
||||
git config --local user.name "GitHub Action"
|
||||
git commit -m "Compile sourcepawn" -a
|
||||
- name: Push changes
|
||||
uses: ad-m/github-push-action@master
|
||||
with:
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
.idea
|
||||
result*
|
||||
.direnv
|
||||
25
LICENSE
Normal file
25
LICENSE
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
Copyright (c) 2020 Robin Appelman <robin@icewind.nl>
|
||||
|
||||
Permission is hereby granted, free of charge, to any
|
||||
person obtaining a copy of this software and associated
|
||||
documentation files (the "Software"), to deal in the
|
||||
Software without restriction, including without
|
||||
limitation the rights to use, copy, modify, merge,
|
||||
publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software
|
||||
is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice
|
||||
shall be included in all copies or substantial portions
|
||||
of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
|
||||
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
|
||||
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
||||
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
16
README.md
Normal file
16
README.md
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
# SdrConnect
|
||||
|
||||
Chat command to connect to the server via sdr
|
||||
|
||||
## Installation
|
||||
|
||||
[Download Plugin](https://github.com/spiretf/sdrconnect/raw/main/plugin/sdrconnect.smx)
|
||||
|
||||
## Usage
|
||||
|
||||
- Enable the plugin
|
||||
- Type `!sdr` in chat
|
||||
|
||||
# Credits
|
||||
|
||||
Part of the plugin is based on [`ServerHop`](https://github.com/JoinedSenses/TF2-ServerHop) and inspired by the [serveme sdr command](https://github.com/Arie/TF2-ServerHop).
|
||||
84
flake.lock
generated
Normal file
84
flake.lock
generated
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
{
|
||||
"nodes": {
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1711217620,
|
||||
"narHash": "sha256-GGHuUQoSsGN/BJYEu7fY+Qzipwq3NqChjlUtT3eg33s=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "ebbe1c1299faf63fffdf1e2a6ebfe43c56b2e691",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"id": "nixpkgs",
|
||||
"ref": "release-23.11",
|
||||
"type": "indirect"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"nixpkgs": "nixpkgs",
|
||||
"spire": "spire",
|
||||
"utils": "utils"
|
||||
}
|
||||
},
|
||||
"spire": {
|
||||
"inputs": {
|
||||
"nixpkgs": [
|
||||
"nixpkgs"
|
||||
],
|
||||
"utils": [
|
||||
"utils"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1711219822,
|
||||
"narHash": "sha256-gVxfFaWqK04qIqjGIZnGWE/0QTr5wZdeGudlGqnDfVI=",
|
||||
"owner": "spiretf",
|
||||
"repo": "nix",
|
||||
"rev": "6007526a96065796476a0b489fe0e259adae1bb9",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "spiretf",
|
||||
"repo": "nix",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"systems": {
|
||||
"locked": {
|
||||
"lastModified": 1681028828,
|
||||
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"utils": {
|
||||
"inputs": {
|
||||
"systems": "systems"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1710146030,
|
||||
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
||||
36
flake.nix
Normal file
36
flake.nix
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
{
|
||||
inputs = {
|
||||
utils.url = "github:numtide/flake-utils";
|
||||
nixpkgs.url = "nixpkgs/release-23.11";
|
||||
spire.url = "github:spiretf/nix";
|
||||
spire.inputs.nixpkgs.follows = "nixpkgs";
|
||||
spire.inputs.utils.follows = "utils";
|
||||
};
|
||||
|
||||
outputs = {
|
||||
self,
|
||||
nixpkgs,
|
||||
utils,
|
||||
spire,
|
||||
}:
|
||||
utils.lib.eachSystem spire.systems (system: let
|
||||
overlays = [spire.overlays.default];
|
||||
pkgs = (import nixpkgs) {
|
||||
inherit system overlays;
|
||||
};
|
||||
inherit (pkgs) lib;
|
||||
spEnv = pkgs.sourcepawn.buildEnv (with pkgs.sourcepawn.includes; [sourcemod]);
|
||||
in rec {
|
||||
packages = rec {
|
||||
inherit spEnv;
|
||||
sdrconnect = pkgs.buildSourcePawnScript {
|
||||
name = "sdrconnect";
|
||||
src = ./plugin/sdrconnect.sp;
|
||||
};
|
||||
default = sdrconnect;
|
||||
};
|
||||
devShells.default = pkgs.mkShell {
|
||||
nativeBuildInputs = with pkgs; [spEnv];
|
||||
};
|
||||
});
|
||||
}
|
||||
BIN
plugin/sdrconnect.smx
Normal file
BIN
plugin/sdrconnect.smx
Normal file
Binary file not shown.
84
plugin/sdrconnect.sp
Normal file
84
plugin/sdrconnect.sp
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
#pragma semicolon 1
|
||||
#include <sourcemod>
|
||||
|
||||
// player connected trough favorites or connect string
|
||||
bool clientConnectedDirectly[MAXPLAYERS+1];
|
||||
|
||||
char serverIp[40];
|
||||
|
||||
|
||||
public Plugin:myinfo = {
|
||||
name = "sdrconnect",
|
||||
author = "Icewind",
|
||||
description = "Chat command to connect to the server via sdr",
|
||||
version = "0.1",
|
||||
url = "https://spire.tf"
|
||||
};
|
||||
|
||||
public OnPluginStart() {
|
||||
char clientConnectMethod[64];
|
||||
for (int client = 1; client <= MaxClients; client++) {
|
||||
if (IsClientInGame(client) && !IsFakeClient(client)) {
|
||||
GetClientInfo(client, "cl_connectmethod", clientConnectMethod, sizeof(clientConnectMethod));
|
||||
|
||||
if (!StrEqual(clientConnectMethod, "serverbrowser_internet")) {
|
||||
clientConnectedDirectly[client] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnClientPutInServer(int client) {
|
||||
char clientConnectMethod[64];
|
||||
GetClientInfo(client, "cl_connectmethod", clientConnectMethod, sizeof(clientConnectMethod));
|
||||
if (!StrEqual(clientConnectMethod, "serverbrowser_internet")) {
|
||||
clientConnectedDirectly[client] = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnClientDisconnect(int client) {
|
||||
clientConnectedDirectly[client] = false;
|
||||
}
|
||||
|
||||
public Action OnClientSayCommand(int client, const char[] command, const char[] sArgs) {
|
||||
if (strcmp(sArgs, "!sdr", false) == 0) {
|
||||
CreateTimer(0.1, HandleCommand, client);
|
||||
}
|
||||
|
||||
return Plugin_Continue;
|
||||
}
|
||||
|
||||
public Action HandleCommand(Handle Timer, int client) {
|
||||
retrieveServerIp();
|
||||
PrintToChatAll("\x01[\x03SDR\x01]: connect %s", serverIp);
|
||||
|
||||
if (clientConnectedDirectly[client]) {
|
||||
Panel panel = new Panel();
|
||||
panel.SetTitle("SDR");
|
||||
panel.DrawText("Re-connect through SDR?");
|
||||
panel.CurrentKey = 3;
|
||||
panel.DrawItem("Accept");
|
||||
panel.DrawItem("Decline");
|
||||
panel.Send(client, MenuConfirmHandler, 15);
|
||||
} else {
|
||||
PrintToChat(client, "\x01[\x03SDR\x01] Due to Valve game change, clients must connect via connect string or favorites to be redirected by server.");
|
||||
}
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public MenuConfirmHandler(Menu menu, MenuAction action, int client, int choice) {
|
||||
if (choice == 3) {
|
||||
ClientCommand(client, "redirect %s", serverIp);
|
||||
}
|
||||
}
|
||||
|
||||
public void retrieveServerIp() {
|
||||
char status[1024];
|
||||
char lines[3][100];
|
||||
char ips[8][50];
|
||||
ServerCommandEx(status, sizeof(status), "status");
|
||||
ExplodeString(status, "\n", lines, sizeof(lines), sizeof(lines[]));
|
||||
ExplodeString(lines[2], " ", ips, sizeof(ips), sizeof(ips[]));
|
||||
strcopy(serverIp, sizeof(serverIp), ips[3]);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue