Hello guys,
before to start: this is an idea and shouldn't be taken as absolute workflow! use at your own risk
for me programming in sourcepawn is really slow, at least the way I was coding was a headache
1. code
2. compile
3. upload files via ftp
4. start server or refresh plugins
5. test and if error try again
...pff
Why not encourage the use of GIT? and maybe discuss one or more types of structures for git projects:
I propose 2 types(yea are basics):
type 1 "big plugin"
Code:
addons
sourcemod
gamedata...
plugins...
include...
cfg
...
type 2 "simple plugin"
This can help with:
1. automate installations
2. CLI terminal creation
- sm compile => compile current git project
- sm debug => compile && upload files to local test server
- sm deploy => compile && upload files to remote test server
- sm release => compile && upload files to remote producion server
3. all the benefits of GIT, Github or whatever want to use for manage a project
- for example: in github we have workflows, this can be used to verify if a plugin compiled correctly when a user wants to contribute
4. Improvement coding practices
5. Fast code, fast test, fast results...
So I will tell you about my progress:
My current work stack:
- Windows10(v2004) & Ubuntu using WSL-2
- Linux GSM
- VsCode with Remote WSL for code
I code this tools that I write for type 2(basic plugin):
Script for primitive CLI(sm_tools.sh)
use in git project with type 2(basic plugin):
- sm compile
- sm debug
- sm deploy
- sm release
PHP Code:
#!/bin/bash
# here replace your new path
deploy_command="/home/alejandro/gameservers/l4d2/deploy.sh"
function str_replace() {
# $1 search
# $2 replace
# $3 string
# example:
# str_replace "include/" "" "include/file.sp"
# return: file.sp
echo "${3/$1/$2}"
}
# Compila todos
function compile_edited_files() {
if git rev-parse --git-dir > /dev/null 2>&1; then
directory=$(git rev-parse --show-toplevel)
# Cambiando a directorio principal
cd $directory
# Archivos modificados
files_edited=$(git status -s | cut -c 4- | grep -P ".sp$|.inc$")
compiler="$(pwd)/spcomp64"
compile_path="$(pwd)/compiled"
files_compiled=()
function compile_file() {
local filename=$1
if [[ ! "${files_compiled[@]}" =~ "${filename}" ]]; then
printf "\nCompiling: $filename\n\n"
path="$(pwd)/$filename"
$compiler $path -D $compile_path -v 2 -i
files_compiled+=($filename)
printf "\n"
fi
}
for file_edited in $files_edited; do
if [[ $file_edited =~ ^include ]];
then
include_file=$(str_replace "include/" "" $file_edited)
include_file=$(str_replace ".inc" "" $include_file)
scripts=$(ls | grep -P ".sp$")
for script in $scripts; do
contains=$(cat $script | grep "^#include <$include_file>")
if [ -n "$contains" ]; then
compile_file $script
fi
done
else
compile_file $file_edited
fi
done
else
echo "The current directory is not a folder with git"
fi
}
function debug() {
if git rev-parse --git-dir > /dev/null 2>&1; then
echo "Updating compiled files to the server"
cd $(git rev-parse --show-toplevel)
local compile_path="$(pwd)/compiled"
cd $compile_path
cp -R * /home/alejandro/gameservers/l4d2/serverfiles/left4dead2/addons/sourcemod/plugins
else
echo "The current directory is not a folder with git"
fi
}
function release() {
# here replace your path
$deploy_command "user_production"
}
function deploy() {
# here replace your path
$deploy_command "user_test"
}
work_type=$1
if [[ "${work_type}" =~ "compile" ]]; then
compile_edited_files
elif [[ "${work_type}" =~ "debug" ]]; then
debug
elif [[ "${work_type}" =~ "deploy" ]]; then
deploy
elif [[ "${work_type}" =~ "release" ]]; then
release
fi
Script for PUSH from Local to Remote(deploy.sh)
Install lftp:
PHP Code:
sudo apt-get install lftp
Require:
- user($1)
Use: ./deploy "remote-username"
PHP Code:
#!/bin/bash
PORT=21
HOST="yourhost.com"
USER=$1
addons_path_source="$HOME/gameservers/l4d2/serverfiles/left4dead2/addons"
addons_path_target="/home/$USER/serverfiles/left4dead2/addons"
cfg_path_source="$HOME/gameservers/l4d2/serverfiles/left4dead2/cfg"
cfg_path_target="/home/$USER/serverfiles/left4dead2/cfg"
function lftp_sync() {
lftp -u $USER "sftp://$HOST:$PORT" -e "
lcd $addons_path_source
mirror --reverse --delete --verbose $addons_path_source $addons_path_target
lcd $cfg_path_source
mirror --reverse --delete --verbose $cfg_path_source $cfg_path_target
bye
"
}
lftp_sync
ssh $USER@$HOST -p $PORT './l4d2server restart'
echo "Correct $USER has been synchronized"
for use this files you need to download and save in any folder you want, remember if you want to test them you will need to update the files by the corresponding paths...
I recommend you add these files to bash aliases, whit sm_tools.sh it's enough:
PHP Code:
alias sm=/home/alejandro/gameservers/l4d2/sm_tools.sh
Current problems(very evidents):
1. Non-dynamic paths
2. Still requiring includes from sourcemod in git project, I exclude this files in .gitignore
Solutions:
1. Make a config file in the user profile(like: /home/user/.smconf => file conf)
2. Save sourcemod inside a folder in the user profile(like: /home/user/.smfiles => folder)
could it be this post the start of a primitive idea?
ps1. I know there are some tools like spedit, but what I want more is a CLI terminal.
ps2. If I don't make all the project, it's because I don't have much time, but maybe this encourage to people with time to make this.
thanks!