Giter VIP home page Giter VIP logo

django_game_server's Introduction

基于Django的游戏服务端框架

Author Email
shutong9527 [email protected]
说明:此后端框架适合中小型,H5游戏。

环境配置

服务器框架Nginx + Superviosr + uWsgi + gevent + docker 框架

import uwsgi
from uwsgidecorators import timer
from django.utils import autoreload

@timer(3)
def change_code_gracefully_reload(sig):
    if autoreload.code_changed()
        uwsgi.reload()
        
  • master分支代表正式环境,dev分支代表测试环境

框架模型

逻辑模型 逻辑模型

  • 通过在APP目录下新建models文件夹,在__init__.py里面导入,实现models的解耦。
  • 游戏指令前两个字段表示指令所在模块,到了具体模块之后再通过具体的指令解析出具体的操作函数
  • 日志系统(settings.py)
# about logging refer to : https://docs.djangoproject.com/en/1.9/topics/logging/
LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'verbose': {
            'format': "[%(levelname)s] [%(asctime)s] [%(name)s:%(lineno)s] %(message)s",
            'datefmt': "%d/%b/%Y %H:%M:%S"
        },
        'simple': {
            'format': "[%(levelname)s] [%(asctime)s] %(message)s",
            'datefmt': "%d/%b/%Y %H:%M:%S"
        },
    },
    'handlers': {
        'debug': {
            'level': 'DEBUG',
            'class': 'logging.FileHandler',
            'filename': 'log/django/debug.log',
            'formatter': 'verbose'
        },
        'info': {
            'level': 'INFO',
            'class': 'logging.handlers.TimedRotatingFileHandler',
            'filename': 'log/game/info.log',
            'formatter': 'simple',
            # 每天备份一次,备份20天内的日志
            'when': "D",
            'interval': 1,
            "backupCount": 20,
            "encoding": "utf8"
        },
        'error': {
            'level': 'ERROR',
            'class': 'logging.handlers.TimedRotatingFileHandler',
            'filename': 'log/game/error.log',
            'formatter': 'verbose',
            'when': "D",
            'interval': 1,
            "backupCount": 20,
            "encoding": "utf8"
        },
    },
    'loggers': {
        'django': {
            'handlers': ['debug'],
            'propagate': True,
            'level': 'DEBUG',
        },
        'game': {
            'handlers': ['info', 'error'],
            'level': 'INFO',
        },
    }
}

说明

代码做提供思路只用,具体按实际项目进行设计。

django_game_server's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.