-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added everything to make it have basic functionality.
- Loading branch information
1 parent
38e0cad
commit a619265
Showing
7 changed files
with
109 additions
and
11 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,41 @@ | ||
//go:build windows | ||
|
||
package console | ||
|
||
import ( | ||
"context" | ||
"github.com/UserExistsError/conpty" | ||
"io" | ||
) | ||
|
||
type Console struct { | ||
stdout io.Writer | ||
commandLine string | ||
conPTY *conpty.ConPty | ||
ExitCode uint32 | ||
} | ||
|
||
func New(exePath string, stdout io.Writer) *Console { | ||
return &Console{ | ||
commandLine: exePath, | ||
stdout: stdout, | ||
} | ||
} | ||
|
||
func (c *Console) Run() error { | ||
var err error | ||
c.conPTY, err = conpty.Start(c.commandLine) | ||
if err != nil { | ||
return err | ||
} | ||
defer c.conPTY.Close() | ||
|
||
go io.Copy(c.stdout, c.conPTY) | ||
|
||
c.ExitCode, err = c.conPTY.Wait(context.Background()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
This file was deleted.
Oops, something went wrong.
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,17 @@ | ||
package main | ||
|
||
import "github.com/jensvandewiel/gosteamcmd" | ||
|
||
func main() { | ||
//this code follows the steps of: https://www.rustafied.com/how-to-host-your-own-rust-server | ||
cmd := gosteamcmd.New() | ||
cmd.Prompts = append(cmd.Prompts, gosteamcmd.ForceInstallDir("c:\\rustserver\\")) | ||
cmd.Prompts = append(cmd.Prompts, gosteamcmd.Login("", "")) | ||
cmd.Prompts = append(cmd.Prompts, gosteamcmd.AppUpdate(258550, "", false)) | ||
//running it headless means it will not output anything | ||
err := cmd.RunHeadless() | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
} |
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 |
---|---|---|
@@ -1,3 +1,8 @@ | ||
module github.com/jensvandewiel/gosteamcmd | ||
|
||
go 1.20 | ||
|
||
require ( | ||
github.com/UserExistsError/conpty v0.1.1 // indirect | ||
golang.org/x/sys v0.8.0 // indirect | ||
) |
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
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,6 @@ | ||
# This is a W.I.P. project, so it's not finished yet. | ||
|
||
To use you must have steamcmd instaled and added it to your path, for now you can only use the library from windows | ||
|
||
## Contribute | ||
I would love to see people contributing to this project, so if you want to contribute just fork the project and make a pull request. |
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 |
---|---|---|
@@ -1,9 +1,35 @@ | ||
package gosteamcmd | ||
|
||
import ( | ||
"github.com/jensvandewiel/gosteamcmd/console" | ||
"os" | ||
) | ||
|
||
type SteamCMD struct { | ||
prompts *[]Prompt | ||
// Prompts contains all the commands that will be executed. | ||
Prompts []*Prompt | ||
console *console.Console | ||
} | ||
|
||
func New() *SteamCMD { | ||
return &SteamCMD{} | ||
return &SteamCMD{ | ||
Prompts: make([]*Prompt, 0), | ||
} | ||
} | ||
|
||
func (s *SteamCMD) RunHeadless() error { | ||
cmd := "steamcmd" | ||
|
||
for _, prompt := range s.Prompts { | ||
cmd += " +" + prompt.FullPrompt | ||
} | ||
|
||
cmd += " +quit" | ||
|
||
s.console = console.New(cmd, os.Stdout) | ||
err := s.console.Run() | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} |