Skip to content
This repository was archived by the owner on Jan 15, 2024. It is now read-only.

Commit 26fbc2a

Browse files
committed
Initial Commit
0 parents  commit 26fbc2a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+11331
-0
lines changed

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.vscode
2+
node_modules
3+
test
4+
5+
plugin/addons
6+
plugin/build.ps1
7+
plugin/sourcemod.js.smx
8+
test.js

CNAME

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sourcemod.js.org

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 infinixius
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<p align="center">
2+
<img src="https://infinixi.us/sourcemod.js/assets/logo_shadow.png">
3+
</p>
4+
5+
A JavaScript wrapper over SourceMod.
6+
7+
# Installation
8+
```
9+
npm install sourcemod.js
10+
```
11+
12+
First of all, install [MetaMod: Source](https://www.sourcemm.net/) and [SourceMod](https://www.sourcemod.net/) onto your Source server. Any version over **1.10** should work. Run your server and ensure SourceMod is working by running `sm version`.
13+
14+
Head over to the [releases](https://github.com/Infinixius/sourcemod.js/releases), and grab the latest plugin download. Drop it in `tf\addons\sourcemod\plugins`.
15+
16+
The plugin also uses [clugg's `sm-json`](https://github.com/clugg/sm-json) and [peace-maker's `sm-websocket`](https://github.com/peace-maker/sm-websocket) to communicate with the JavaScript plugin over WebSockets. Go ahead and install them to your server.
17+
18+
You should see the following if it worked:
19+
```
20+
[SMJS] sourcemod.js loaded!
21+
[SMJS] Started WebSocket server on port 12345!
22+
```
23+
24+
You can also run the console command `smjs_test`:
25+
```
26+
[SMJS] Test!
27+
```
28+
29+
# Examples
30+
31+
```js
32+
import { Server } from "sourcemod.js"
33+
34+
const server = await new Server("ws://localhost:12345")
35+
server.connect()
36+
37+
server.on("ready", async () => {
38+
console.log("Connected!")
39+
server.players.on("connect", (player) => {
40+
console.log(`${player.name} connected!`)
41+
})
42+
server.players.on("disconnect", (player) => {
43+
console.log(`${player.name} disconnected!`)
44+
})
45+
})
46+
47+
// node test.js
48+
// Connected!
49+
// infinixius connected!
50+
// infinixius disconnected!
51+
```
52+
53+
Documentation is available at [https://infinixi.us/sourcemod.js](https://infinixi.us/sourcemod.js).
54+
55+
# Contributing
56+
57+
Before creating an issue or pull request, please ensure that it hasn't already been reported or suggested, and double-check the [docs](https://infinixi.us/sourcemod.js).
58+
59+
Other than that, feel free to contribute! Bugfixes, new features, or just better code in general are all greatly appreciated!
60+
61+
# License
62+
63+
This project is under the [MIT License](https://mit-license.org/). This allows you to use, modify, and distribute the source code as long as you include the license.
64+
65+
# Troubleshooting
66+
67+
### `Exception reported: Invalid match index passed.`
68+
69+
This is an issue with `sm-websockets`. Use [this version](https://github.com/peace-maker/sm-websocket/files/7966813/websocket.zip) I built myself that contains the fix, or just build it yourself.
70+
71+
### `Error: connect ECONNREFUSED`
72+
73+
This error boils down to the JavaScript plugin not being able to connect to the WebSocket server. This could be for several reasons:
74+
75+
- The SourceMod server isn't up
76+
- The SourceMod plugin isn't working
77+
- The port (`12345`) is taken by another service, or isn't port forwarded properly. (you need to port forward this port if you aren't accessing the WebSocket server from a LAN connection)
78+
- You aren't connected to the internet

0 commit comments

Comments
 (0)