- add service file\n- add config file system
This commit is contained in:
parent
74542329f2
commit
7988bb936e
3 changed files with 159 additions and 32 deletions
104
mewny.rb
104
mewny.rb
|
|
@ -18,6 +18,14 @@ VERSION = {
|
|||
:FIL_TXT => '0.01',
|
||||
:FIL_CUP => '0.02',
|
||||
:FIL_CO8 => '0.30',
|
||||
|
||||
:CFL_PORT => 'port',
|
||||
:CFL_SV_F => 'save-file',
|
||||
:CFL_SV_T => 'save-interval',
|
||||
:CFL_ROWS => 'rows',
|
||||
:CFL_COLS => 'cols',
|
||||
:CFL_DUMB => 'call-me-stupid',
|
||||
:CFL_PRIV => 'private',
|
||||
}
|
||||
|
||||
options = {
|
||||
|
|
@ -29,8 +37,47 @@ options = {
|
|||
:cols => 40,
|
||||
:file => nil,
|
||||
:file_lockout => false,
|
||||
:file_interval => 600,
|
||||
:file_interval => 600.0,
|
||||
}
|
||||
|
||||
def parse_svfile f, options
|
||||
return options if options[:file_lockout]
|
||||
options[:file_lockout] = true
|
||||
file_stuff = {
|
||||
:name => f,
|
||||
:text => '',
|
||||
:color => [],
|
||||
:cursor => 0,
|
||||
:writeme => false
|
||||
}
|
||||
unless File.exist? f
|
||||
file_stuff[:writeme] = true
|
||||
options[:file] = file_stuff
|
||||
options[:file_lockout] = false
|
||||
return options
|
||||
end
|
||||
File.readlines(f, chomp: true).each do |msg|
|
||||
ver, msg = msg.chomp.split('|',2)
|
||||
next if msg.nil?
|
||||
case ver
|
||||
when VERSION[:FIL_TXT]
|
||||
file_stuff[:text] = msg
|
||||
when VERSION[:FIL_CO8]
|
||||
msg.each_char.with_index do |c, i|
|
||||
next unless c =~ /[0-7]/
|
||||
file_stuff[:color] << {
|
||||
:co8 => 7
|
||||
} until file_stuff[:color].length > i
|
||||
file_stuff[:color][i][:co8] = c.to_i.clamp(0,7)
|
||||
end
|
||||
when VERSION[:FIL_CUP]
|
||||
file_stuff[:cursor] = msg.to_i
|
||||
end
|
||||
end
|
||||
options[:file] = file_stuff
|
||||
options
|
||||
end
|
||||
|
||||
OptionParser.new do |opt|
|
||||
opt.on('-pPORT', '--port PORT', Integer,
|
||||
'Port to serve/listen on (defaults to 7570)') do |o|
|
||||
|
|
@ -70,6 +117,7 @@ OptionParser.new do |opt|
|
|||
'(server only) Serve publicly, rather than privately. Please ONLY add this option if you entierly know what you\'re doing and have permission from/are the server owner. Say please to expose.'
|
||||
) do |o|
|
||||
if o == "please"
|
||||
puts 'I_AM_STUPID enabled'
|
||||
options[:server_host] = PUBLIC_HOST
|
||||
end
|
||||
end
|
||||
|
|
@ -82,40 +130,34 @@ OptionParser.new do |opt|
|
|||
opt.on('-f FILE', '--save-file FILE',
|
||||
'(server only) File to read initial state from and save state to.'
|
||||
) do |f|
|
||||
break if options[:file_lockout]
|
||||
options[:file_lockout] = true
|
||||
file_stuff = {
|
||||
:name => f,
|
||||
:text => '',
|
||||
:color => [],
|
||||
:cursor => 0,
|
||||
:writeme => false
|
||||
}
|
||||
unless File.exist? f
|
||||
file_stuff[:writeme] = true
|
||||
options[:file] = file_stuff
|
||||
options[:file_lockout] = false
|
||||
next
|
||||
options = parse_svfile(f, options)
|
||||
end
|
||||
opt.on('-C FILE', '--config-file FILE',
|
||||
'(server only) File to set all other config options from.'
|
||||
) do |f|
|
||||
File.readlines(f, chomp: true).each do |msg|
|
||||
next if msg.start_with? '#'
|
||||
ver, msg = msg.chomp.split('|',2)
|
||||
next unless msg != nil
|
||||
next if msg.nil?
|
||||
case ver
|
||||
when VERSION[:FIL_TXT]
|
||||
file_stuff[:text] = msg
|
||||
when VERSION[:FIL_CO8]
|
||||
msg.each_char.with_index do |c, i|
|
||||
next unless c =~ /[0-7]/
|
||||
file_stuff[:color] << {
|
||||
:co8 => 7
|
||||
} until file_stuff[:color].length > i
|
||||
file_stuff[:color][i][:co8] = c.to_i.clamp(0,7)
|
||||
end
|
||||
when VERSION[:FIL_CUP]
|
||||
file_stuff[:cursor] = msg.to_i
|
||||
when VERSION[:CFL_PORT]
|
||||
options[:port] = msg.to_i
|
||||
when VERSION[:CFL_SV_F]
|
||||
options = parse_svfile(msg, options)
|
||||
when VERSION[:CFL_SV_T]
|
||||
options[:file_interval] = msg.to_f
|
||||
when VERSION[:CFL_ROWS]
|
||||
options[:rows] = msg.to_i
|
||||
when VERSION[:CFL_COLS]
|
||||
options[:cols] = msg.to_i
|
||||
when VERSION[:CFL_DUMB]
|
||||
next unless msg == 'please'
|
||||
puts 'I_AM_STUPID enabled'
|
||||
options[:server_host] = PUBLIC_HOST
|
||||
when VERSION[:CFL_PRIV]
|
||||
options[:server_host] = PRIVATE_HOST
|
||||
end
|
||||
end
|
||||
options[:file] = file_stuff
|
||||
end
|
||||
opt.on('-h', '--help', 'Get help with this command') do
|
||||
puts opt
|
||||
|
|
@ -306,7 +348,7 @@ def do_server(file_opts)
|
|||
next
|
||||
end
|
||||
ver, msg = msg.chomp.split('|',2)
|
||||
next unless msg != nil
|
||||
next if msg.nil?
|
||||
case ver
|
||||
when VERSION[:CLN_TXT]
|
||||
newtext << clean_chars(msg)
|
||||
|
|
@ -441,7 +483,7 @@ def do_client
|
|||
msg = socket.gets
|
||||
exit 0 unless msg
|
||||
ver, msg = msg.split('|',2)
|
||||
next unless msg != nil
|
||||
next if msg.nil?
|
||||
case ver
|
||||
when VERSION[:SRV_TXT]
|
||||
row,col,chars = msg.split('|',3)
|
||||
|
|
|
|||
66
various/mewny.conf
Normal file
66
various/mewny.conf
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
# This is an example config file for
|
||||
# a mewny server. I warn against
|
||||
# putting spaces at the end of lines
|
||||
# as that may cause confusion to you
|
||||
# or the program. Note that despite
|
||||
# being formatted mostly like the
|
||||
# mewny protocol, this is unlike
|
||||
# that protocol in that
|
||||
# 1. This file is NOT necessarily
|
||||
# forwards compatible with future
|
||||
# versions of this software.
|
||||
# 2. This file uses octothorpes (#) to
|
||||
# denote comments.
|
||||
# 3. This file uses human-readable
|
||||
# 'version' strings before the
|
||||
# initial bar.
|
||||
# I hope you find this configuration
|
||||
# file useful :3
|
||||
# The paragraph below will describe
|
||||
# how this document is formatted.
|
||||
|
||||
# This is a comment describing an option
|
||||
# The option is placed below with a
|
||||
# sensable or its default value like
|
||||
# so...
|
||||
#option|sensible-or-default-value
|
||||
|
||||
# Set the port
|
||||
#port|7570
|
||||
|
||||
# Number of rows in the grid
|
||||
#rows|24
|
||||
|
||||
# Number of columns in the grid
|
||||
#cols|40
|
||||
|
||||
# Expose this instance to the world
|
||||
# Only do this if you are very stupid
|
||||
# or entirely know what you are doing.
|
||||
# Set the value past the bar to 'please'
|
||||
# (without quotes) to make this work
|
||||
# as described.
|
||||
# The command line option for this
|
||||
# is --expose-this-instance-for-the
|
||||
# -world-to-see-because-I-know-what
|
||||
# -I'm-doing and accepts an argument
|
||||
# which preferably says please.
|
||||
#call-me-stupid|if-you-*Have*-to
|
||||
|
||||
# Do not expose this instance to the
|
||||
# world (Opposite of call-me-stupid)
|
||||
# Any value past the bar will enable
|
||||
# this, and it is enabled by default
|
||||
# unless the stupid 'call-me-stupid'
|
||||
# option is enabled.
|
||||
#private|makes-the-dev-happy
|
||||
|
||||
# Save file to write the grid to
|
||||
# This has no default value but is
|
||||
# confgiured to match the service
|
||||
# file below:
|
||||
save-file|/var/lib/mewny/mewny_savefile
|
||||
|
||||
# Save file autosave interval in seconds
|
||||
# 600 seconds is 10m btw
|
||||
#save-interval|600
|
||||
19
various/mewny.service
Normal file
19
various/mewny.service
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
[Unit]
|
||||
Description=Mewny Server
|
||||
After=network.target
|
||||
Documentation=https://git.linuxposting.xyz/mewrrythekibby/mewny
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
ExecStart=mewny --server --config-file /etc/mewny/mewny.conf
|
||||
|
||||
User=mewny
|
||||
Group=mewny
|
||||
WorkingDirectory=/var/lib/mewny
|
||||
|
||||
Restart=always
|
||||
RestartSec=1
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue