def addPlayer(self, player):
     """添加一个用户
     """
     if self._players.has_key(player.pid):
         log.msg("reconnectioned, pid: %s" % player.pid)
         self.getPlayerByID(player.pid).reconnection(player.sid)
         return
     log.msg("game add player %s" % player.sessionno)
     self._players[player.pid] = player
 def dropPlayer(self, player):
     """处理用户下线
     """
     userId = player.pid
     try:
         #保存数据
         player.saveDataToDb()
         del self._players[userId]
         log.msg("removed player %s from PlayerManager" % userId)
     except Exception, e:
         log.err(e)
Beispiel #3
0
    def task(self):
        """
        任务
        :param kwargs:
        :return:
        """
        log.msg(datetime.datetime.now())
        log.msg('do task. %s' % self.kwargs['name'])
        try:
            n = time.time()
            for conn in GlobalObject(
            ).netfactory.connmanager._connections.values():
                log.msg("uid: %s. ctime:%s. room_id: %s." %
                        (getattr(conn.instance, 'uid',
                                 None), getattr(conn.instance, "ctime", None),
                         getattr(conn.instance, 'room_id', None)))

                if (getattr(conn.instance,'uid',None) is None or getattr(conn.instance,'room_id', None) is None) and\
                    getattr(conn.instance, "ctime", None) is not None:
                    if (n - conn.instance.ctime) > 30:
                        GlobalObject().netfactory.loseConnection(conn.id)
                        log.msg("%s dead conn %s delete" %
                                (GlobalObject().json_config['name'], conn.id))
        except BaseException, e:
            log.err("=======================fight dead conn error")
            log.err("%s" % e)
Beispiel #4
0
def allocGameNode(data):
    """
    用户登陆成功后分配一个game node服务节点
    :param userId:
    :return:
    """
    #用户ID做key
    try:
        gamenode = GameNodeRouter().get_node(data['pid'])
        if gamenode:
            log.msg("allocGameNode successful. node: %s" % gamenode.getName())
            gamenode.callbackChildNotForResult("gameMsgRouter", data)
        else:
            log.err("can't find gamenode. data: %s" % data)
    except GameNodeRouterException:
        log.err("GameNodeRouterException no gamenode to use. data: %s" % data)
Beispiel #5
0
def forwarding(data):
    """
    转发数据到对应节点
    :param data:
    :return:
    """
    #用户ID做key
    try:
        gamenode = GameNodeRouter().get_node(data['pid'])
        if gamenode:
            log.msg("forwarding data. node: %s" % gamenode.getName())
            gamenode.callbackChildNotForResult("gameMsgRouter", data)
        else:
            log.err("can't find gamenode. data: %s" % data)
    except GameNodeRouterException:
        log.err("GameNodeRouterException no gamenode to use. data: %s" % data)
def stopHandler():
    """
    服务器关闭处理
    :return:
    """
    log.msg(u'server %s is stop ing...' % GlobalObject().json_config['name'])
    log.msg(u'syncdb...')
    for player in PlayerManager().getAllPlayers().values():
        log.msg("%s sync player %s" % (GlobalObject().json_config['name'], player.uid))
        player.saveDataToDb()
Beispiel #7
0
#coding:utf8
from gfirefly.server.globalobject import GlobalObject
from gfirefly.server.logobj import log

#导入逻辑接口
import common_api
import root_api


def doConnectionMade(conn):
    '''当连接建立时调用的方法'''
    print 'do some thing. 1111111'


def doConnectionLost(conn):
    '''当连接断开时调用的方法'''
    print 'do some thing. 2222222'


GlobalObject().wsapp.doConnectionMade = doConnectionMade  #将自定义的登陆后执行的方法绑定到框架
GlobalObject().wsapp.doConnectionLost = doConnectionLost  #将自定义的下线后执行的方法绑定到框架

log.msg("net_node api: %s" % GlobalObject().wsapp.service._targets.keys())
Beispiel #8
0
 def saveDataToDb(self):
     """
     持久化用户数据
     :return:
     """
     log.msg("saveDataToDb %s" % self.pid)
Beispiel #9
0
 def initDataFromDb(self):
     """
     加载数据
     :return:
     """
     log.msg("init data %s" % self.pid)
#coding=utf-8
from gfirefly.server.globalobject import GlobalObject
from gfirefly.utils.services import CommandService
from gfirefly.server.logobj import log
from app.game_node.core.playermanager import PlayerManager

#自定义服务器通道
gamecommandservice = CommandService("gamecommandservice")
setattr(GlobalObject(), "gamecommandservice", gamecommandservice)

#导入逻辑接口
from api import common_api

def stopHandler():
    """
    服务器关闭处理
    :return:
    """
    log.msg(u'server %s is stop ing...' % GlobalObject().json_config['name'])
    log.msg(u'syncdb...')
    for player in PlayerManager().getAllPlayers().values():
        log.msg("%s sync player %s" % (GlobalObject().json_config['name'], player.uid))
        player.saveDataToDb()


GlobalObject().stophandler = stopHandler

log.msg("game api: %s" % gamecommandservice._targets.keys())
Beispiel #11
0
#coding:utf8
from gfirefly.server.globalobject import GlobalObject
from gfirefly.server.logobj import log

#导入逻辑接口
import common_api

log.msg("gate_node api: %s" % GlobalObject().root.service._targets.keys())