Commits

Alexandre Macabies committed 6cd505f

skin_proxy now useless; install.y for minecraft; fixed setup.py for servers.dat

Comments (0)

Files changed (3)

     'presencesync_usermap': { 'uid': 20130,
                               'groups': ('presencesync_usermap',
                                          'presencesync_public',) },
+    'minecraft': { 'uid': 20140, 'groups': ('minecraft',) },  # FIXME: needs presencesync?
 }
 
 # Same with groups. *_public groups are used for services that need to access
     'homepage': 20110,
     'redmine': 20120,
     'presencesync_usermap': 20130,
+    'minecraft': 20140,  # FIXME: needs _public?
 }
 
 
     install_systemd_unit('hfs@')
 
 
+def install_minecraft():
+    requires('libprologin')
+    requires('nginxcfg')
+    requires('presencesync')
+
+    install_cfg_profile('minecraft', group='minecraft')
+
+    mkdir(
+        '/var/prologin/minecraft',
+        mode=0o755, owner='minecraft:minecraft'
+    )
+
+    copy(
+        'minecraft/static',
+        '/var/prologin/minecraft/static',
+        mode=0o755, owner='minecraft:minecraft'
+    )
+    mkdir(
+        '/var/prologin/minecraft/static/resources',
+        mode=0o755, owner='minecraft:minecraft'
+    )
+
+    with cwd('/var/prologin/minecraft'):
+        # download static resources once (this takes time!)
+        # and create shared servers.dat
+        os.system('python setup.py')
+
+    copy(
+        'minecraft/server',
+        '/var/prologin/minecraft/server',
+        mode=0o700, owner='minecraft:minecraft'
+    )
+
+    install_nginx_service('minecraft-skins')
+    install_nginx_service('minecraft')
+
+    install_systemd_unit('minecraft-skins')
+    install_systemd_unit('minecraft')
+
+    # TODO:
+    # for each user machine:
+    #   mkdir ~/.minecraft
+    #   ln -s /var/prologin/minecraft/static/bin ~/.minecraft/bin
+    #   ln -s /var/prologin/minecraft/static/resources ~/.minecraft/resources
+    #   ln -s /var/prologin/minecraft/static/servers.dat ~/.minecraft/servers.dat
+    #   provide the minecraft/client/*.py tools for the user
+
 
 COMPONENTS = [
     'libprologin',
     'presencesync_usermap',
     'rfs',
     'hfs',
+    'minecraft',
 ]
 
 

minecraft/server/skin_proxy.py

 # You should have received a copy of the GNU General Public License
 # along with Prologin-SADM.  If not, see <http://www.gnu.org/licenses/>.
 
+
+########################################################################
+# THIS FILE CAN BE IGNORED. YOU SHOULD USE NGINX CAPABILITIES INSTEAD. #
+# See nginx/services/minecraft-skins.nginx                             #
+########################################################################
+
+
 import os
 import prologin.config
 import tornado.ioloop

minecraft/setup.py

 import requests
 from lxml import etree
 from io import BytesIO
+from nbt import *
 
 RES_CFG = prologin.config.load('minecraft')
 
             logging.debug("Downloaded resource: %s (%d bytes)", path, size)
 
 
+def write_servers_dat():
+    nbtfile = NBTFile()
+    nbtfile.name = ''
+    root = TAG_List(type=TAG_Compound, name='servers')
+    prolocraft = TAG_Compound()
+    prolocraft.tags.append(TAG_Byte(name='hideAddress', value=0))
+    prolocraft.tags.append(TAG_String(name='name', value=RES_CFG['server']['human_name']))
+    prolocraft.tags.append(TAG_String(name='ip', value=RES_CFG['server']['host']))
+    root.tags.append(prolocraft)
+    nbtfile.tags.append(root)
+    nbtfile.write_file(
+        buffer=open(os.path.join(RES_CFG['resources']['static_dir'], 'servers.dat'), 'wb'))
+
+
 if __name__ == '__main__':
+    write_servers_dat()
     download_resources()