Skip to content

Commit

Permalink
upload
Browse files Browse the repository at this point in the history
  • Loading branch information
MCausc78 committed Feb 4, 2024
0 parents commit cb0f069
Show file tree
Hide file tree
Showing 12 changed files with 809 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.v]
indent_style = tab
7 changes: 7 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
* text=auto eol=lf
*.bat eol=crlf

**/*.v linguist-language=V
**/*.vv linguist-language=V
**/*.vsh linguist-language=V
**/v.mod linguist-language=V
58 changes: 58 additions & 0 deletions .github/workflows/jekyll-gh-pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Sample workflow for building and deploying a Jekyll site to GitHub Pages
name: Deploy Jekyll with GitHub Pages dependencies preinstalled

on:
# Runs on pushes targeting the default branch
push:
branches: ["master"]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write

# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false

jobs:
# Build job
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Pages
uses: actions/configure-pages@v4
- name: Setup V
uses: nocturlab/setup-vlang-action@v1
with:
id: v
v-version: master
- name: Bulid docs
run: v gendocs.vsh
- name: Build with Jekyll
uses: actions/jekyll-build-pages@v1
with:
source: ./docs
destination: ./_site
- name: Upload artifact
uses: actions/upload-pages-artifact@v2

# Deployment job
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v3
20 changes: 20 additions & 0 deletions .github/workflows/lib_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Library tests

on: [push, pull_request]

jobs:
library_tests:
name: Run library tests
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup V
uses: nocturlab/setup-vlang-action@v1
with:
id: v
v-version: master

- name: Test library
run: v test src/
33 changes: 33 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Binaries for programs and plugins
main

*.exe
*.exe~
*.so
*.dylib
*.dll

# Ignore binary output folders
bin/

# Ignore common editor/system specific metadata
.DS_Store
.idea/
.vscode/
*.iml

# ENV
.env

# vweb and database
*.db
/*.js

/test.v
/test*.v
*.def
/*.c
/*.db
/test*.py
/test.py
/test*.vsh
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# rcon.v

RCON client in V

[Documentation](https://darphome.github.io/rcon.v/rcon.html)

## Example

```v
import rcon
fn main() {
// `rcon.connect_tcp` parameter is string in address:port format
mut client := rcon.connect_tcp('127.0.0.1:25575')!
defer {
client.close() or {}
}
// perform authentication. it may return 'invalid password' error
client.login('mypassw0rd')!
// execute command. returns string as result
client.execute('say Hello world')!
players := client.execute('list')!
println('Players on server: ${players}')
}
```
224 changes: 224 additions & 0 deletions examples/interactive_client.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
module main

import cli
import os
import regex
import rcon
import term

struct Colorizer {
mut:
pattern regex.RE
}

fn (mut c Colorizer) colorize(x string) string {
return c.pattern.replace_by_fn(x, fn (_ regex.RE, s string, start int, end int) string {
c := s[end - 1]
f := match c {
`0` {
fn () string {
return term.format_esc('30')
}
}
`1` {
fn () string {
return term.format_esc('34')
}
}
`2` {
fn () string {
return term.format_esc('32')
}
}
`3` {
fn () string {
return term.format_esc('36')
}
}
`4` {
fn () string {
return term.format_esc('31')
}
}
`5` {
fn () string {
return term.format_esc('35')
}
}
`6` {
fn () string {
return term.format_esc('93')
}
}
`7` {
fn () string {
return term.format_esc('90')
}
}
`8` {
fn () string {
return term.format_esc('90')
}
}
`9` {
fn () string {
return term.format_esc('94')
}
}
`a` {
fn () string {
return term.format_esc('392')
}
}
`b` {
fn () string {
return term.format_esc('96')
}
}
`c` {
fn () string {
return term.format_esc('91')
}
}
`d` {
fn () string {
return term.format_esc('95')
}
}
`e` {
fn () string {
return term.format_esc('33')
}
}
`f` {
fn () string {
return term.format_esc('37')
}
}
`r` {
fn () string {
return term.format_esc('0')
}
}
`k` {
fn () string {
return ''
}
}
`l` {
fn () string {
return term.format_esc('1')
}
}
`o` {
fn () string {
return term.format_esc('3')
}
}
`n` {
fn () string {
return term.format_esc('4')
}
}
`m` {
fn () string {
return term.format_esc('9')
}
}
else {
panic('invalid character (${c})')
}
}
return f()
})
}

fn new_colorizer() Colorizer {
mut pattern := regex.new()
pattern.compile_opt('(§[0-9a-frlonmk])') or { panic(err) }
return Colorizer{
pattern: pattern
}
}

@[params]
struct ApplicationParams {
address string
port int
password string
raw bool
}

fn run_application(params ApplicationParams) ! {
mut client := rcon.connect_tcp('${params.address}:${params.port}')!
defer {
client.close() or {}
}
mut colorizer := new_colorizer()
client.login(params.password)!
for {
print('$ ')
command := os.input('').trim_space()
if command in ['Q', 'q'] {
break
}
if command == '' {
continue
}
r := client.execute(command)!
if params.raw {
println(r)
} else {
println(colorizer.colorize(r))
}
}
}

fn main() {
mut app := cli.Command{
name: 'rcon-client'
description: 'interactive RCON client'
execute: fn (cmd cli.Command) ! {
address := cmd.flags.filter(|c| c.name == 'address')[0].get_string()!
port := cmd.flags.filter(|c| c.name == 'port')[0].get_int()!
password := cmd.flags.filter(|c| c.name == 'password')[0].get_string()!
raw := cmd.flags.filter(|c| c.name == 'raw')[0].get_bool() or { false }
run_application(address: address, port: port, password: password, raw: raw)!
}
flags: [
cli.Flag{
flag: .string
name: 'address'
abbrev: 'a'
description: 'the address to use when connecting'
required: false
default_value: ['127.0.0.1']
},
cli.Flag{
flag: .int
name: 'port'
abbrev: 'P'
description: 'the port to use when connecting'
required: false
default_value: ['25575']
},
cli.Flag{
flag: .string
name: 'password'
abbrev: 'p'
description: 'the password to use when authenticating'
required: true
},
cli.Flag{
flag: .bool
name: 'raw'
abbrev: 'r'
description: 'whether to print raw responses, if not present, they will automatically colorized'
required: false
default_value: ['false']
},
]
}
app.setup()
app.parse(os.args)
}
9 changes: 9 additions & 0 deletions gendocs.vsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import os

println('Generating docs...')
if os.system('v doc -color -f html -o docs/ -readme src/') != 0 {
eprintln('HTML docs generation failed')
exit(1)
} else {
println('HTML docs successfully generated!')
}
Loading

0 comments on commit cb0f069

Please sign in to comment.