Compare commits

..

12 Commits

16 changed files with 3658 additions and 2 deletions

View File

@@ -6,7 +6,7 @@ conf={}
confp=os.path.expanduser('~/.config/swat.cfg') # This won't work on Windows. You'll need to tweak this to run it on Windows. Not my problem.
defaults={'classes':[(1,3),(1,3),(1,3),(1,3),(1,3),(1,3),(1,3),(0,0),(0,0),(1,3),(1,3),(1,3)],'guns':[(1,3),(1,3),(1,3),(1,3),(1,3),(0,0),(0,0),(1,3)],'armour':[(1,3),(1,3),(1,3),(1,3)],'traits':[(1,3),(1,3),(1,3),(1,3),(1,3),(1,3),(1,3),(1,3),(1,3),(1,3),(1,3),(1,3),(1,3),(1,3),(1,3),(1,3)],'specs':[(1,3),(1,3),(1,3),(1,3),(1,3),(1,3),(1,3),(1,3),(1,3)],'talents':[(12,12),(1,3),(1,3),(1,3),(1,3),(1,3),(1,3)],'medals':{}}
defaults={'classes':[(1,3),(1,3),(1,3),(1,3),(1,3),(1,3),(1,3),(0,0),(0,0),(1,3),(1,3),(1,3)],'guns':[(1,3),(1,3),(1,3),(1,3),(1,3),(0,0),(0,0),(1,3)],'armour':[(1,3),(1,3),(1,3),(1,3)],'traits':[(1,3),(1,3),(1,3),(1,3),(1,3),(1,3),(1,3),(1,3),(1,3),(1,3),(1,3),(1,3),(1,3),(1,3),(1,3),(1,3)],'specs':[(1,3),(1,3),(1,3),(1,3),(1,3),(1,3),(1,3),(1,3),(1,3)],'talents':[(12,12),(1,3),(1,3),(1,3),(1,3),(1,3),(1,3)],'medals':{},'saves':{}}
def add_user(name):
namehash=encode.hash_name(name) # Store the hash so that if they request a different name that happens to have the same hash, it can just be stored together.
if namehash in conf: conf[namehash]['names'].add(name)
@@ -158,7 +158,7 @@ def lookup_piece(piece,table,name,partial=False):
if not partial:
try: return table.index(p)
except ValueError: raise LookupException(f"Couldn't resolve {piece} from {name}")
res=list(filter(lambda x:p in x,table))
res=list(filter(lambda x:x.startswith(p),table))
if len(res)!=1: raise LookupException(f"Couldn't resolve {piece} with partial match from {name} (found {len(res)} possibilities)") # Ambiguous lookups not allowed
return table.index(res[0])
class LookupException(Exception): pass
@@ -170,6 +170,15 @@ def ranks():
print(f'{o[0]}: {o[1][0]}/{o[1][1]}',end=', ')
print()
def savebuild(code,name):
pass
def builds():
pass
def medals():
pass
load_conf()

View File

@@ -35,4 +35,5 @@ def muxhero(clas,trait,spec):
def muxmedals(key,moh=-1,pcc=-1,cob=-1,lsa=-1,rem=-1):
print(key,moh,pcc,cob,lsa,rem)
if moh!=-1: return key+moh*2+pcc*4+cob*8+lsa*16+rem*32
print(bool(key&1),bool(key&2),bool(key&4),bool(key&8),bool(key&16),key//32)
return bool(key&1),bool(key&2),bool(key&4),bool(key&8),bool(key&16),key//32

21
swat-codegen/PKGBUILD Normal file
View File

@@ -0,0 +1,21 @@
# Maintainer: Zergling_man, from fedora.email
pkgname=swat-codegen
pkgver=1.1.1
pkgrel=1
pkgdesc="A simple CLI interface to RCPDv3, the rank code management service for the game SWAT: Aftermath"
arch=('any')
url=http://rakka.au/contact
license=('WTFPL+nigger')
depends=('jq' 'curl' 'coreutils' 'grep')
source=()
sha256sums=('SKIP') #Don't know how to use this on a repo.
package() {
cd ${pkgdir}
install -d usr/bin opt/swat-codegen
cd ${srcdir}/${pkgname}
chmod a+x codegen.sh
cp class gun armour trait spec talent codegen.sh ${pkgdir}/opt/swat-codegen
ln -s /opt/swat-codegen/codegen.sh /${pkgdir}/usr/bin/rcpd
}

4
swat-codegen/armour Normal file
View File

@@ -0,0 +1,4 @@
Light
Medium m
Heavy h
Advanced Cyborg Watchman a

12
swat-codegen/class Normal file
View File

@@ -0,0 +1,12 @@
Sniper gs ss
Medic
Tactician
Psychologist
Maverick
HeavyOrdnance ho
Demolitions
Cyborg
Pyrotechnician
Watchman wm
TechOps techies tech
UmbrellaClone gal alice

112
swat-codegen/codegen.sh Executable file
View File

@@ -0,0 +1,112 @@
#!/bin/bash
loc=$(dirname $(readlink -f "$0"))
account_server_root_url=https://swataftermath.com:8443
code_server_root_url=https://swataftermath.com:9443/account
# TOKEN MANAGEMENT
function migrate
{
curl "$account_server_root_url/account/$1/activate-migrated" --json '{"currentPassword":"'"$3"'","emailAddress":"'"$2"'","newPassword":"'"$3"'"}'
curl "$account_server_root_url/account/$1/verify-email" --json '{"verificationCode":"'"$(cat)"'"}'
login "$1" "$3"
}
function login
{
[ -n "$2" ] || { echo "Please provide a username and password, in that order, when calling this"; exit; }
curl $account_server_root_url/login --json '{"username":"'"$1"'","password":"'"$2"'"}' > ~/.config/rcpd.cfg
}
function get_token
{
cat ~/.config/rcpd.cfg 2>/dev/null || { echo "Please login first" >&2; exit; }
}
# CORE API CALLS
function get
{
TOKE=`get_token`
curl -H "Authorization:Bearer $TOKE" $code_server_root_url/$1
}
function post
{
TOKE=`get_token`
curl -$3H "Authorization:Bearer $TOKE" $code_server_root_url/$1 --json "$2"
}
function delete_code
{
TOKE=`get_token`
curl -H "Authorization:Bearer $TOKE" $code_server_root_url/rank-code/$1 -X DELETE
}
# UTILS
function lookup
{
w=
matches=`grep -ic "${*:2}" $loc/$1`
if [ "$matches" -ne 1 ]; then
echo "$1 '${*:2}' is ambiguous (got $matches matches), trying whole-word match" >&2
# Attempt whole-word match and see if we get exactly one result (and then remember it has happened!!!)
w=w
word_matches=`grep -ic$w "${*:2}" $loc/$1`
if [ "$word_matches" -ne 1 ]; then echo "still ambiguous (got $word_matches matches)" >&2; return 1; fi
fi
read $1 garbage <<< "`grep -i$w "${*:2}" $loc/$1`"
}
# USER-FACING COMMANDS
function builds
{
filter='.[] | .rankCode+" "+.buildName'
if [ -n "$1" ]; then filter='.[] | select(.buildName=="'"$*"'")'; fi
get saved-builds | jq "$filter"
}
function save
{
if [ -n "$2" ]; then name=',"buildName":"'"${*:2}"'"'; fi
res=`post rank-code '{"rankCode":"'$1'"'"$name"'}' i`
created=`head -n 1 <<< "$res" | cut -d' ' -f2`
res=`tr -d '\r' <<< "$res" | awk -F '\r\n' 'BEGIN { a=1 } a==0 { print } $0=="" { a=0 }'`
jq <<< "$res"
if [ $created = 201 -a -z "$2" ]; then delete_code $1; fi # Don't bother storing any build that doesn't have a name if it didn't already exist. Assume it's just logging the results of a game.
}
function generate
{
# mfw I actually have to do work
IFS=/ read -a hero <<< "$*"
length=${#hero[*]}
if [ $length -eq 6 ]; then IFS=/ read class gun armour trait spec talent <<< "$*"
elif [ $length -eq 5 ]; then IFS=/ read class armour trait spec talent <<< "$*"
elif [ $length -eq 4 ]; then IFS=/ read class trait spec talent <<< "$*"; fi # Probably a borg or a wm.
if [ -z "$gun" ]; then
if [ "${class%wm}" != "$class" ]; then gun=${class%wm}; class=wm
elif [ "${class%mav}" != "$class" ]; then gun=${class%mav}; class=mav; fi
fi
res=0
lookup class "$class"
res=$((res+$?))
if [ -z "$gun" ]; then gun=$class; fi # Do this after qualifying class so I don't have to nest the full class table in the gun table.
lookup gun "$gun"
res=$((res+$?))
if [ -z "$armour" ]; then armour=$class; fi
lookup armour "$armour"
res=$((res+$?))
lookup trait "$trait"
res=$((res+$?))
lookup spec "$spec"
res=$((res+$?))
lookup talent "$talent"
res=$((res+$?))
if [ $res -gt 0 ]; then echo "Please correct above errors and try again"; exit; fi
echo $class $gun $armour $trait $spec $talent
post generate '{"swatClass":"'$class'","gun":"'$gun'","armor":"'$armour'","trait":"'$trait'","specialization":"'$spec'","talent":"'$talent'"}' | jq '.rankCode//.'
}
# DO SHIT
"$@"

File diff suppressed because it is too large Load Diff

8
swat-codegen/gun Normal file
View File

@@ -0,0 +1,8 @@
AssaultRifle a ar Medic Tactician Psychologist
SniperRifle s sr TechOps
Chaingun c cg HeavyOrdnance Cyborg
RocketLauncher r rl Demolitions
Flamethrower f ft Pyrotechnician
LaserRifle lr
GatlingLaser gl
Pistols fists UmbrellaClone

2206
swat-codegen/openapi.yaml Normal file

File diff suppressed because it is too large Load Diff

9
swat-codegen/spec Normal file
View File

@@ -0,0 +1,9 @@
Weaponry
PowerArmor pa
EnergyCells
Cybernetics
Triage
Chemistry
Leadership
Robotics
Espionage

7
swat-codegen/talent Normal file
View File

@@ -0,0 +1,7 @@
Courage crg
Wiring wire
Running
Spotting
Toughness
Tinkering
Hacking

16
swat-codegen/trait Normal file
View File

@@ -0,0 +1,16 @@
Skilled
Gifted
Survivalist
Dragoon
Acrobat
SwiftLearner sl
Healer
FlowerChild fc
ChemReliant cr
RadResistant rr
Gadgeteer
Prowler
Energizer energiser
PackRat pr
Engineer
Reckless