Fix color output on mcrcon

This commit is contained in:
spengreb 2019-10-08 21:49:05 +02:00
parent 8861ac7ac0
commit 25bd47bf12

View file

@ -20,14 +20,13 @@ class VouchersController < ApplicationController
def create
# Logic for creating a voucher
output = ""
whitelist = `mcrcon -H mine.vereto.net -p #{ENV["MC_RCON_PASS"]} "whitelist list" | sed 's/There are*.*whitelisted players: //g'`.gsub('', "").gsub("\n", "")
whitelist = whitelist.split(", ")
whitelist = `mcrcon -c -H mine.vereto.net -p #{ENV["MC_RCON_PASS"]} "whitelist list" | sed 's/There are*.*whitelisted players: //g'`.split(", ")
if Voucher.exists?(vouchee: params[:voucher]) && params[:voucher].in?(whitelist)
@voucher = Voucher.new(voucher_params)
if @voucher.save
output = `mcrcon -H mine.vereto.net -p #{ENV["MC_RCON_PASS"]} "whitelist add #{params[:vouchee]}"`
output = `mcrcon -c -H mine.vereto.net -p #{ENV["MC_RCON_PASS"]} "whitelist add #{params[:vouchee]}"`
render json: { :message => output }.to_json, status: :created, location: @voucher
else
render json: @voucher.errors, status: :unprocessable_entity