Skip to content
This repository has been archived by the owner on May 12, 2020. It is now read-only.

Commit

Permalink
add basic features
Browse files Browse the repository at this point in the history
  • Loading branch information
kafuuchino-desu authored Nov 6, 2018
1 parent fabc64b commit d8e295f
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 9 deletions.
8 changes: 5 additions & 3 deletions mcdlog.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ def errlog(data):
print(PREFIX + data)
traceback.print_exc()

def exitlog(data, crit=0, traceback=0):
def exitlog(data, crit=0, traceback=''):
if crit == 0:
print(PREFIX + data)
print(PREFIX + 'Exiting...')
if crit == 1:
print(PREFIX + 'Critical Error Occured')
print(PREFIX + 'Reason:' + data)
if traceback == 1:
traceback.print_exc()
if traceback != '':
print(traceback)
print(PREFIX + 'Exiting...')


50 changes: 50 additions & 0 deletions mcgit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash
# -*- coding: utf-8 -*-
#this file includes the mcgit object

import configparser
import json
from gittle import Gittle
from mcdlog import *

helpmsg = '''------thanks for use mcgit------
those are basic functions:
!!mcg help -show this help message
!!mcg commit list -show a list of commits available
!!mcg commit [info] -reboot the server and commit current world
!!mcg rollback [commit] -reboot the server and rollback the world to a commit
!!mcg branch now -show which branch the server is on now
!!mcg branch list -show all branches avaliable
!!mcg branch change [branch] -reboot and change the server to another branch
(the world now will commit with info 'changebranch')
!!mcg branch delete [branch] -delete a branch
(if you are deleting the branch server is running on,the server will load master branch after reload)
!!mcg merge [branch] -merge the branch to master
--------------------------------'''

class mcgit(object):
def __init__(self):
conf = configparser.ConfigParser()
try:
conf.read('mcgit.properties')
except:
log('mcgit failed to read a config file.Creating a new one')
conf.add_section('savePath')
conf.set('savePath', 'path', './mcgit')
#try:
#saveRepo = Gittle.init(conf.get('savePath','path'))
#except:
#exitlog('failed to init world repo...', 1, traceback.format_exc())

def onServerInfo(self, server, info):
if (info.isPlayer == 0):
pass
else:
if info.content.startswith('!!mcg'):
args = info.content.split(' ')
if (args[1] == 'help'):
for line in helpmsg.splitlines():
server.tell(info.player, line)



1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
gittle==0.5.0
30 changes: 24 additions & 6 deletions server.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
#!/bin/bash
# -*- coding: utf-8 -*-
# this file includes basic minecraft server class functions

from subprocess import Popen, PIPE
import select
import fcntl, os
import time
import sys
import traceback
#import mcdplugin #still in develop
from mcdlog import *
import mcgit
from mcdlog import *
import serverinfoparser

def notice():
print('thanks for using MCDaemon,it\'s open source and u can find it here:')
Expand All @@ -35,7 +38,8 @@ def tick(self):
if line[11:].startswith('[Server Watchdog/FATAL]: A single server tick took 60.00 seconds (should be max 0.05)'):
exitlog('single tick took too long for server and watchdog forced the server off', 1)
sys.exit(0)
mcgithandler.onServerInfo()
result = serverinfoparser.parse(line)
mcgithandler.onServerInfo(server,result)
'''
for singleplugin in plugins.plugins():
singleplugin.onServerInfo()
Expand Down Expand Up @@ -77,10 +81,16 @@ def stop(self):
self.cmdstop()
try:
self.forcestop()
print('forced server to stop')
log('forced server to stop')
except:
pass
def say(self, data):
self.execute('say ' + data)
def tell(self, player, data):
self.execute('tellraw '+ player + ' {"text":"' + data + '"}')
if __name__ == "__main__":
notice()
Expand All @@ -94,9 +104,17 @@ def stop(self):
errlog('error initalizing plugins,printing traceback')
sys.exit(0)
'''
server = Server()
mcgithandler= mcgit()
try:
server = Server()
except:
exitlog('failed to initalize the server.', 1, traceback.format_exc())
sys.exit(0)
try:
mcgithandler= mcgit.mcgit()
except:
exitlog('failed to initalize plugins.', 1, traceback.format_exc())
server.stop()
sys.exit(0)
while True:
try:
server.tick()
Expand Down
34 changes: 34 additions & 0 deletions serverinfoparser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash
# -*- coding: utf-8 -*-
#this file is for handleing server info and parsing those info into a object

import re

class parseResult(object):
def __init__(self):
self.hour = 0
self.min = 0
self.sec = 0
self.sourceProcess = ''
self.isPlayer = 0
self.player = ''
self.message = ''

def parse(line):
result = parseResult()
result.hour = line[1:3]
result.min = line[4:6]
result.sec = line[7:9]
result.sourceProcess = re.search(r'[[](.*?)[]]', line[11:]).group()[1:-1]
if (result.sourceProcess == 'Server thread/INFO') and (line[33:].startswith('<')):
player = re.search(r'[<](.*?)[>]', line[33:]).group()[1:-1]
if player != '':
result.isPlayer = 1
result.player = player
content = line[33:].replace('[' + result.sourceProcess + ']: ', '' , 1)
result.content = content.replace('<' + result.player + '> ', '', 1)
else:
result.isPlayer = 0
result.player = ''
result.content = line[11].replace('[' + result.sourceProcess + ']: ' , '' , 1)
return result

0 comments on commit d8e295f

Please sign in to comment.