python开发游戏脚本_Python开发游戏开服脚本
#!/usr/bin/env python
#coding:utf-8
from pymongo import MongoClient
import datetime
import random
import shutil
import time
import sys
import re
import os
class readyTostart(object):
def Countdown(self):
print('''
######################################
# 拜见包大人一健开服脚本 #
######################################
''')
print(' \033[1;31;40m脚本即将开始执行...\033[0m')
time.sleep(2)
for i in range(3,0,-1):
time.sleep(1)
print(' 脚本还有\033[5;31;40m%s\033[0m秒开始执行,请稍等...' % i)
def ParametersCheck(self):
global openNum,openYear,openMonth,openDay
try:
openNum = sys.argv[1]
if not re.match('^[0-9]+$', openNum):
if not re.match('(^[0-9]+)-([0-9]+$)', openNum):
print('Please output in the specified format. Example num1-num2,Does not support decimals')
sys.exit(1)
else:
parmet1 = re.match('(^[0-9]+)-([0-9]+$)', openNum)
if int(parmet1.group(1)) > int(parmet1.group(2)):
print('The first opening number %s cannot be greater than the second opening number %s' % (parmet1.group(1),parmet1.group(2)))
sys.exit(1)
if re.match('^[0]', openNum):
print('You cannot enter numbers starting with 0')
sys.exit(1)
except Exception as e:
print e
values = sys.argv[0]
print('Please enter at least one parameter')
Exaples = 'Exaples: python {key} 10 | python {key} 1-10'
print(Exaples.format(key=values))
sys.exit(1)
nowDate = datetime.datetime.now() + datetime.timedelta(days=1)
openYear = nowDate.strftime("%Y")
try:
cusDate = sys.argv[2]
except Exception as e:
cusDate = nowDate
openMonth = cusDate.strftime("%m")
openDay = cusDate.strftime("%d")
if re.match('0\d', openMonth): openMonth = openMonth[1:]
if re.match('0\d', openDay): openDay = openDay[1:]
else:
if not re.match('^[0-9]+\.[0-9]+',cusDate):
print 'The second parameter format is => month.day'
sys.exit(1)
openMonth = cusDate.split('.')[0]
openDay = cusDate.split('.')[1]
if int(openMonth) < 1 or int(openMonth) > 12:
print 'The month you entered cannot be greater than twelve and less than one'
sys.exit(1)
if int(openDay) < 1 or int(openDay) > 31:
print("You can't enter more than 31 or less than 1")
sys.exit(1)
openMonth = '=' + openMonth
openDay = '=' + openDay
class deployService(object):
def __init__(self):
self.toolsdirctory = '/data/tools/new_server/'
self.servicedir = '/data/bz-tw-and/s'
self.codedir = '/data/bz-tw-and'
self.logdir = '/data/logs/s'
self.userInputSpecified = []
self.userInputall = []
self.alreadyExist = []
def startDeploy(self):
global inputNum,newService,scriptList
if not os.path.exists(self.codedir):
print('%s not exists,script exit' % self.codedir)
sys.exit(0)
if not os.path.exists(self.toolsdirctory + 'Config.lua') or not os.path.exists(self.toolsdirctory + 'bin'):
print('(%s and %s)file or dirctory not exists,script exit' % (self.toolsdirctory + 'Config.lua', self.toolsdirctory + 'bin'))
sys.exit(1)
inputNum = re.match('(\d+)-(\d+)', openNum)
inputOnenum = re.match('(^[1-9][0-9]*$)', openNum)
if inputOnenum:
num = 1
for i in os.listdir(self.codedir):
nowService = re.match('(s)(\d+)',i)
if nowService:
num += 1
nowNum = i[1:]
if openNum == nowNum:
print(' %s Service already existsService already exists' % openNum)
sys.exit()
newNum = str(num) + '-' + openNum
inputNum = re.match('(\d+)-(\d+)', newNum)
if inputNum:
oneNum = int(inputNum.group(1))
towNum = int(inputNum.group(2))
for fuNum in range(1,towNum+1):
self.userInputall.append(fuNum)
for fuNum in range(oneNum,towNum+1):
self.userInputSpecified.append(fuNum)
for i in os.listdir(self.codedir):
nowService = re.match('(s)(\d+)',i)
if nowService:
nowNum = i[1:]
if int(nowNum) < towNum:
self.alreadyExist.append(int(nowNum))
differenceSet=(set(self.userInputall)^set(self.alreadyExist))
intersection=(set(self.userInputSpecified)&set(self.alreadyExist))
newService=list(differenceSet)
oldService=list(intersection)
oldService=list(intersection)
if newService != []:
for i in newService:
gameService = self.servicedir + str(i)
os.mkdir(gameService)
shutil.copytree(self.toolsdirctory + 'bin', gameService + '/bin')
shutil.copytree(self.servicedir + str(1) + '/scripts', self.servicedir + str(i) + '/scripts')
shutil.copyfile(self.toolsdirctory + 'Config.lua',gameService +'/Config.lua')
if not os.path.exists(self.logdir +str(i)):
os.mkdir(self.logdir +str(i))
os.symlink(self.logdir+str(i),self.servicedir + str(i) + '/bin/logs')
if not os.path.exists(self.toolsdirctory + '/bin/bz-tw-and-s_'):
print('%s not exists,Please Check' % (self.toolsdirctory + '/bin/bz-tw-and-s_'))
try:
shutil.move(self.servicedir + str(i) + '/bin/bz-tw-and-s_',self.servicedir + str(i) + '/bin/bz-tw-and-s' + str(i))
except Exception as e:
print e
print('%s服修改bz-tw-and-s_命名失败' % i)
scriptList = ['hotup.sh','hotup_client.sh','start.sh','stop.sh']
for scriptName in scriptList:
if not os.path.exists(self.servicedir+str(i) + '/bin/' + scriptName):
print('%s not exists,Please Check' % scriptName)
hotupLine = ''
hotupPort = 10000 + int(i)
for scriptName in ['hotup.sh','hotup_client.sh']:
with open(self.servicedir + str(i) + '/bin/' + scriptName, 'r')as f:
for line in f.readlines():
if line.find('10000'):
line = re.sub('10000', str(hotupPort), line)
hotupLine += line
else:
hotupLine += line
with open(self.servicedir + str(i) + '/bin/' + scriptName, 'w')as f:
f.write(hotupLine)
hotupLine = ''
start_stop_Line = ''
for scriptName in ['start.sh','stop.sh']:
with open(self.servicedir + str(i) + '/bin/' + scriptName, 'r')as f:
for line in f.readlines():
if line.find('1'):
line = re.sub('1', str(i), line)
start_stop_Line += line
else:
start_stop_Line += line
with open(self.servicedir + str(i) + '/bin/' + scriptName, 'w')as f:
f.write(start_stop_Line)
start_stop_Line = ''
if oldService != []:
for i in oldService:print(' already kai fu %s' % i)
else:
print('Exaples: python %s 10 | python %s 1-10' % (sys.argv[0],sys.argv[0]))
class MongoDabase(object):
def __init__(self,serverIp='192.168.6.184',databasePort=27017,user='root',password='123456',adminDatabase='admin'):
self.client = MongoClient(serverIp,databasePort)
self.db = self.client[adminDatabase]
self.db.authenticate(user,password)
def createPassword(self):
password = ''
for i in range(8):
current = random.randrange(0,8)
if current > i:
temp = random.randint(0,9)
elif current < i:
temp = chr(random.randint(65,90))
else:
temp = chr(random.randint(97,122))
password += str(temp)
return password
def createUser(self):
global passwordList
passwordList = {}
deploy = deployService()
configfileLine = ''
passwordPath = '/data/script/'
if not os.path.exists(passwordPath):
os.mkdir(passwordPath)
print(' \033[1;31;40m部署情况如下\033[0m')
if newService != []:
for i in newService:
clientPort = 20000 + int(i)
httpPort = 10000 + int(i)
dbName = 's' + str(i)
SvrId = str(i)
gameServiceName = 'bz-tw-and-s' + str(i)
password = self.createPassword()
passwordList.update({i:password})
dbUser = self.client[gameServiceName]
try:
dbUser.command("createUser", "bz", pwd=password, roles=["readWrite"])
except Exception as e:
print(''' %s
请测试账户密码验证是否正确
'''% e)
old = ['20003','10003','s3','zxjRYZGI','sid','2018','=5','=19']
new = [clientPort,httpPort,dbName,password,SvrId,openYear,openMonth,openDay]
for old,new in zip(old,new):
with open(deploy.servicedir + str(i) + '/Config.lua','r')as f:
for line in f.readlines():
if line.find(str(old)):
line = re.sub(str(old),str(new),line)
configfileLine += line
else:
configfileLine += line
with open(deploy.servicedir + str(i) + '/Config.lua', 'w')as f:
f.write(configfileLine)
configfileLine = ''
with open(passwordPath+'mongo_pass.txt','a+')as f:
mongoDbname = 'bz-tw-and-' + str(i)
f.write(mongoDbname+'='+password+'\n')
os.remove(deploy.servicedir + str(i)+'/scripts/Config.lua')
shutil.copyfile(deploy.servicedir + str(i) + '/Config.lua',deploy.servicedir + str(i)+'/scripts/Config.lua')
print(' \033[31m%s\033[0m 服已经部署完成...' % i)
print(' \033[1;31;40m数据库密码文件存放位置如下\033[0m')
print(' /data/script/mongo_pass.txt')
class configCheck(object):
def luaConfigcheck(self):
deploy = deployService()
Month = openMonth[1:]
Day = openDay[1:]
data = ['(GAME_IO_LISTEN_PORT = )(\d+)',
'(GAME_HTTP_LISTEN_PORT=)(\d+)',
'(DBNAME="bz-tw-and-)(.*)(")',
'(DBPWD=")(.*)(")',
'(SvrId = )(.*)',
'(activityStartDate={year=)(\d{4})(,month=)(\d+)(,day=)(\d+)(.*)']
if newService != []:
for i in newService:
print ('''
############################################
# %s服配置文件检查 #
############################################
''' % i)
with open(deploy.servicedir + str(i) + '/scripts/Config.lua', 'r')as f:
for line in f.readlines():
for d in data:
if re.match(d, line):
m = re.match(d, line)
try:
if int(m.group(2)) == 10000 + int(i) or int(m.group(2)) == 20000 + int(i) or int(m.group(2)) == int(i):
if int(m.group(2)) == int(i):
result = ' [\033[32mID正确\033[0m]'
else:
result = '[\033[32m端口正确\033[0m]'
else:
result = ' [\033[5;31m配置错误\033[0m]'
if int(m.group(2)) == int(openYear) and int(m.group(4)) == int(Month) and int(m.group(6)) == int(Day):
yresult = '[\033[32m年月日正确\033[0m]'
else:
yresult = ' [\033[5;31m年或月或日错误\033[0m]'
except Exception as e:
if str(m.group(2)) == str('s'+str(i)) or str(m.group(2)) == str(passwordList[i]):
if str(m.group(2)) == str(passwordList[i]):
result = ' [\033[32m密码正确\033[0m]'
else:
result = ' [\033[32m名字正确\033[0m]'
else:
result = ' [\033[5;31m配置错误\033[0m]'
try:
time.sleep(0.5)
print(' %s\033[31m%s\033[0m%s\033[31m%s\033[0m%s\033[31m%s\033[0m%s%s' % (m.group(1), m.group(2), m.group(3), m.group(4), m.group(5), m.group(6),m.group(7), yresult))
except Exception as e:
try:
time.sleep(0.5)
print(' %s\033[31m%s\033[0m%s %s' % (m.group(1), m.group(2), m.group(3), result))
except Exception as e:
time.sleep(0.5)
print(' %s\033[31m%s\033[0m %s' % (m.group(1), m.group(2), result))
def scriptCheck(self):
deploy = deployService()
hotup = '(.*:)(\d{5})(/.*)'
startstop = '(.*)(s)(\d+)(")'
if newService != []:
for i in newService:
print ('''
############### %s服脚本检查 ###############
''' % i)
for script_name in scriptList:
with open( deploy.servicedir + str(i) + '/bin/'+ script_name, 'r')as f:
for line in f.readlines():
if re.match(hotup,line):
m = re.match(hotup,line)
if int(m.group(2)) == (10000 + int(i)):
time.sleep(0.5)
result='端口正确'
print(' %s\033[31m%s\033[0m%s [\033[32m%s\033[0m]' % (m.group(1),m.group(2),m.group(3),result))
else:
time.sleep(0.5)
result = '端口错误'
print(' %s\033[31m%s\033[0m%s [\033[5;31m%s\033[0m]' % (m.group(1), m.group(2), m.group(3), result))
if re.match(startstop,line):
m = re.match(startstop, line)
if int(m.group(3)) == (int(i)):
time.sleep(0.5)
result = '开关脚本服数正确'
print(' %s%s\033[31m%s\033[0m%s [\033[32m%s\033[0m]' % (m.group(1), m.group(2), m.group(3), m.group(4), result))
else:
time.sleep(0.5)
result = '开关脚本服数正确'
print(' %s\033[31m%s\033[0m%s [\033[5;31m%s\033[0m]' % (m.group(1), m.group(2), m.group(3), m.group(4), result))
for i in newService:
for file_name in os.listdir(deploy.servicedir + str(i) + '/bin/'):
if re.match('(.*s)(\d+)',file_name):
m = re.match('(.*s)(\d+)',file_name)
if m.group(2) == str(i):
result = '服数正确'
time.sleep(1)
print(" ########## %s服二进制文件命名检查 ##########" % i)
print(" %s\033[31m%s\033[0m [\033[32m%s\033[0m]" % (m.group(1),m.group(2),result))
else:
time.sleep(1)
result = '服数错误'
print(" %s\033[31m%s\033[0m [\033[5;31m%s\033[0m]" % (m.group(1), m.group(2), result))
for i in newService:
print ('''
############### %s软链接人工检查 ###############''' % i)
if os.path.exists(deploy.servicedir + str(i) + '/bin/logs') and os.path.exists(deploy.logdir+str(i)):
print(' \033[32m软链接已存在\033[0m')
os.system('ls -l %s'% (deploy.servicedir + str(i) + '/bin/logs'))
else:
print(' \033[31m软链接目录不存在,请检查\033[0m')
if __name__ == '__main__':
start = readyTostart()
start.ParametersCheck()
start.Countdown()
deploy = deployService()
deploy.startDeploy()
db = MongoDabase()
db.createUser()
check = configCheck()
check.luaConfigcheck()
check.scriptCheck()
python开发游戏脚本_Python开发游戏开服脚本相关推荐
- python开发游戏流程_python开发游戏的前期准备
python开发游戏的前期准备 本文章面向有一定基础的python学习者,使用Pygame包开发一款简单的游戏 首先打开命令行,使用PyPI下载Pygame包(输入命令pip install pyga ...
- python 通用数据库类型_Python开发基础之Python常用的数据类型
博文大纲 一.Python介绍 二.Python的变量 三.Python常用的数据类型 1.数字 2.字符串 3.元组 4.列表 5.字典 一.Python介绍 Python是一种动态解释型的编程语言 ...
- python打砖块游戏算法设计分析_python小游戏--打砖块的实现与讲解(python自学总结系列)...
我在系统地学习了python之后,觉得python带给我很多乐趣,因此在网络平台GitHub上寻找了这个小游戏,这个小游戏是一个很经典的游戏,只是打砖块,但是可以很好地入门并体现python的乐趣. ...
- python开发的著名网站_python开发著名网站_python开发的著名软件 - CSDN
根据权威机构统计,每日Python人才需求高达5000 +,但目前很少有程序员知道Python在市场中,竞争小,很容易得到快速和高薪就业.也许你不太了解十大Python常用的开发工具,现在我将告诉你. ...
- python编辑器是什么_python开发用什么编辑器
如果你想做得好,你必须首先提高工具.据估计,大部分pythoners开始python从python IDE.有许多python IDE工具,但这是一个艰巨的任务选择一个IDE使用.您可以使用最基本的文 ...
- python游戏设计_python小游戏设计入门1-了解游戏
从小到大玩过很多的游戏,在我小时候,能玩游戏的地方不多,那时玩游戏都是偷摸玩的,只要是个游戏就觉得非常有趣,比较经典的有魂斗罗,拳皇,超级玛丽,贪吃蛇,俄罗斯方块等游戏:发展到现在,玩游戏已经成为生活 ...
- linux mine游戏,【Pyramid】Pocketmine开服(win、linux、安卓)日常维护详细教程
您尚未登录,立即登录享受更好的浏览体验! 您需要 登录 才可以下载或查看,没有帐号?注册(register) x 本帖最后由 RapDoodle 于 2014-2-10 22:56 编辑 教程尚未完成 ...
- wow工作室脚本_魔兽世界:怀旧服“脚本”一天收益近千金币,难怪工作室趋之如骛...
#魔兽世界怀旧服#众所周知,魔兽世界怀旧服中有数量众多的脚本工作室,并且随着脚本被开发的越来越"先进",这些工作室在使用脚本的情况下往往可以获得普通玩家难以想象的高额收益,这也导致 ...
- python能用来制作游戏吗_python 做游戏开发怎么样?
郎朗坤 Python并不适合用于游戏开发,有些个别的例子,比如<文明>和<EVE>使用了Python,但这也并说明不了什么.按照一般理解,Python主要适合写小程序,用少量的 ...
最新文章
- 【Java】数据结构之 顺序表(MyArrayList)
- 全球43亿IPv4地址正式耗尽,IPv6才是物联网的菜
- python【力扣LeetCode算法题库】1162- 地图分析(BFS)
- C# 代码优化 性能优化【转】
- Java基础学习总结(70)——开发Java项目常用的工具汇总
- 利用Excel批量快速发送电子邮件
- 2009最新QQ空间密码QQ相册密码破解
- 使用 Mono.Cecil 辅助 Unity3D 手游进行性能测试
- 基于tp5的免费开源企业官网系统
- 手机HTML拼图验证,jQuery支持移动端的滑动块拼图验证插件
- 怎么打开华硕电脑计算机功能,华硕笔记本小键盘怎么开(笔记本电脑虚拟键盘怎么打开)...
- FTP客户端代码解析
- NXP-MPC5748G车载MCU使用(食用)方法(踩坑)实用指南(骗人教程)(二):使用FREERTOS点亮LED
- 随笔之javamail邮件发送(阿里云企业邮箱)
- php空间开启伪静态,php虚拟主机开启伪静态(虚拟主机伪静态规则配置)
- 宠物诊所java项目_JavaWeb项目-宠物诊所管理系统
- 对电脑屏幕进行远程监控和控制有什么方法?
- 使用Maple进行c语言程序修复,Gro¨ bner基方法验证乘法器的Maple实现
- [曾贤志]-Excel数据透视表与SQL技术-曾贤志-专题视频课程
- wpl计算方法_已知权值集合为{5,7,2,3,6,1,4},计算带权路径长度WPL()。
热门文章
- 【毕业设计】jsp+sql毕业选题系统(论文)
- php分类程序,PHP无限分类实现程序_PHP教程
- 50欧姆线设计 高频pcb_高频电路布线的应对方法有哪些?
- Python+OpenCV:交互式图像前景提取(Interactive Foreground Extraction using GrabCut Algorithm)
- 使用Opencv2遇到error: C2061 语法错误 标识符dest
- Halcon 例程学习之频域自相关变换( correlation_fft)
- 预编译头文件(precompiled header)说明
- 力扣(LeetCode)46
- 开发者应该关注的五项Web新兴技术:WebGL和SVG名列其中
- 高性能MySQL读书笔记 (五)