-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 5e7e0c6
Showing
5 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2018 LukWeb | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# SourceLogger | ||
|
||
This is a small program written in Go which redirects | ||
the output of the `srcds_linux` executable to stdout. | ||
|
||
It can be used to fix for the following issue | ||
> stdin and stdout no longer works for linux garry's mod srcds server | ||
For more insights head over to the discussion at | ||
[garraysmod-isse#2343](https://github.com/Facepunch/garrysmod-issues/issues/2343#issue-123386501). | ||
|
||
## How to use | ||
|
||
1. Download the latest release from GitHub | ||
2. Put the file `source_logger` into the same directory as `srcds_linux` | ||
2. Replace in your start script the call of `srcds_linux` or `srcds_run` with `source_logger`. | ||
|
||
An example start script before: | ||
````sh | ||
#!/bin/bash | ||
./srcds_run -maxplayers 16 +gamemode terrortown +map ttt_waterworld | ||
```` | ||
|
||
A start script using SourceLogger | ||
````sh | ||
#!/bin/bash | ||
./source_logger -maxplayers 16 +gamemode terrortown +map ttt_waterworld | ||
```` | ||
|
||
All arguments to `source_logger` will be forwarded to `srcds_linux`, so you can just keep your old arguments. | ||
|
||
#### Drawbacks | ||
|
||
There is a small drawbacks while using this software: | ||
You can't use the _auto update_ feature of the `srcds_run` script, | ||
because the `srcds_linux` executable is called directly from the SourceLogger. | ||
|
||
## How does it work? | ||
This program uses [kr/pty](https://github.com/kr/pty) to create a pseudo console and capture its output. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module SourceLogger | ||
|
||
require github.com/kr/pty v1.1.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
github.com/kr/pty v1.1.3 h1:/Um6a/ZmD5tF7peoOJ5oN5KMQ0DrGVQSXLNwyckutPk= | ||
github.com/kr/pty v1.1.3/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"github.com/kr/pty" | ||
"io" | ||
"os" | ||
"os/exec" | ||
"os/signal" | ||
) | ||
|
||
func main() { | ||
args := os.Args[1:] | ||
|
||
// Calling the srcds_linux executable in the same directory | ||
cmd := exec.Command("./srcds_linux", args...) | ||
|
||
cmd.Stderr = os.Stderr | ||
cmd.Stdout = os.Stdout | ||
cmd.Env = append(cmd.Env, "LD_LIBRARY_PATH=.:bin:"+os.Getenv("LD_LIBRARY_PATH")) | ||
|
||
// Redirecting the SIGINT or SIGKILL signal to the srcds_linux | ||
c := make(chan os.Signal, 1) | ||
signal.Notify(c, os.Interrupt) | ||
go func() { | ||
for sig := range c { | ||
err := cmd.Process.Signal(sig) | ||
if err != nil { | ||
fmt.Printf("[sourcelogger] couldn't redirect signal %v to srcds_linux\n", sig) | ||
} | ||
} | ||
}() | ||
|
||
// Starting the pseudo terminal for catching the stdout of gmod | ||
file, err := pty.Start(cmd) | ||
if err != nil { | ||
fmt.Println("[sourcelogger] could't start the srcds_linux executable") | ||
panic(err) | ||
} | ||
|
||
// Redirecting the output of gmod to the stdout | ||
_, err = io.Copy(os.Stdout, file) | ||
if err != nil { | ||
fmt.Println("[sourcelogger] finished with copy error (nothing to worry about)") | ||
} else { | ||
fmt.Println("[sourcelogger] finished") | ||
} | ||
|
||
} |