Пример #1
0
    def Disconnect(self, sReason):
        timer.Unschedule(self.m_ConnectedFlag)
        logger.Info("%s disconnect r=%s" % (self.m_ID, sReason))
        oMgrServer = service.GetService("ServerManager")
        oTcpServer = oMgrServer.Get("client")
        oTcpServer.Disconnect(self.m_SocketID)

        oLinkMgr = service.GetService("LinkManager")
        oLinkMgr.DelLink(self.m_ID)

        oPlayerMgr = service.GetService('PlayerManager')
        oPlayerMgr.Disconnected(self.m_ProxyID, sReason)
Пример #2
0
 def Disconnected(self, sReason, bForceQuit=False):
     if not bForceQuit:
         self.WaitReconnect()
     else:
         logger.Info("real disconnect %s, r=%s, force=%s" %
                     (self.m_ID, sReason, bForceQuit))
         self.OnDisconnected()
         service.GetService('PlayerManager').DelPlayer(self.m_ID, sReason)
Пример #3
0
 def __init__(self, iSocketID):
     oLinkMgr = service.GetService("LinkManager")
     self.m_ID = oLinkMgr.UpdateID()
     self.m_SocketID = iSocketID
     self.m_ProxyID = 0
     self.m_RecvData = bytes()
     self.m_HeartbeatFlag = "Heartbeat_%s" % (self.m_ID)
     self.m_ConnectedFlag = "Connected_%s" % (self.m_ID)
Пример #4
0
def TimerCheckHeartbeat(iLinkID):
    oLinkMgr = service.GetService("LinkManager")
    oLink = oLinkMgr.GetLink(iLinkID)
    if not oLink:
        return
    if int(time.time()) - oLink.m_Heartbeat < 10:
        return

    oLink.Disconnect("no heartbeat")
Пример #5
0
def OnLoginAccount(oLink, oAccountProtocol):
    if not database.CheckAccountExist(oAccountProtocol.m_User):
        uid = database.RegisterAccount(oAccountProtocol.m_User,
                                       oAccountProtocol.m_Password)
    else:
        ret = database.CheckAccountPassword(oAccountProtocol.m_User,
                                            oAccountProtocol.m_Password)
        if ret:
            oLink.Disconnect("check account fail %s" % str(ret))
            return
        uid = database.RegisterAccount(oAccountProtocol.m_User,
                                       oAccountProtocol.m_Password)
    oPlayerMgr = service.GetService("PlayerManager")
    oPlayer = oPlayerMgr.CreatePlayer(oLink, uid)
    oPlayer.Login()
    oLink.ConnectedFinish()
Пример #6
0
    def __init__(self, sAddress, iPort, sFlag):
        self.m_Address = sAddress
        self.m_Port = iPort
        self.m_Queue = Queue()
        self.m_SendQueue = Queue()
        self.m_QuitQueue = Queue()
        self.m_Epoll = None
        self.m_Sockets = {}
        self.m_SocketID2FD = {}
        self.m_SocketID = 0
        self.m_ServerSocket = socket(AF_INET, SOCK_STREAM)
        self.m_NetThread = threading.Thread(target=NetworkThread,
                                            args=(self, ))
        self.m_CBFunc = {}
        self.m_Running = False

        self.m_Flag = sFlag

        oSMgr = service.GetService("ServerManager")
        oSMgr.Add(sFlag, self)
Пример #7
0
sys.path.append("../server")
sys.path.append("../common")

import serverapp
import sys
import entry
import service
import player


class CCustomPlayer(player.CPlayer):
    def OnLogin(self, bRelink):
        import customprotocol.p_player
        oBaseInfo = customprotocol.p_player.P_BaseInfo()
        oBaseInfo.m_Uid = self.m_ID
        oBaseInfo.m_Name = self.GetName()
        self.SendProtocol(oBaseInfo)

    def OnDisconnected(self):
        pass


app = serverapp.CServerApplication(sys.argv)
app.SetEntry(entry.OnEntry)

service.GetService("PlayerManager").SetCustomPlayerClass(CCustomPlayer)

app.Listen(12349, "0.0.0.0")
app.Exec()
print("Bye!~")
Пример #8
0
 def SendProtocol(self, oProtocol):
     oLinkMgr = service.GetService("LinkManager")
     oLink = oLinkMgr.GetLink(self.m_LinkID)
     if not oLink:
         return
     oLink.SendProtocol(oProtocol)
Пример #9
0
def CheckOffline(iUid):
    oPlayerMgr = service.GetService("PlayerManager")
    oPlayer = oPlayerMgr.GetPlayer(iUid)
    if not oPlayer:
        return
    oPlayer.Disconnected("wait reconnect failed.", True)
Пример #10
0
    def SendProtocol(self, oProtocol):
        oMgrServer = service.GetService("ServerManager")
        oTcpServer = oMgrServer.Get("client")

        data = oProtocol.PacketData()
        oTcpServer.SendData(self.m_SocketID, data)
Пример #11
0
def GetLinkObjectBySocketID(iSocketID):
    oLinkMgr = service.GetService("LinkManager")
    return oLinkMgr.GetLinkBySocketID(iSocketID)
Пример #12
0
def GetLinkObject(iLinkID):
    oLinkMgr = service.GetService("LinkManager")
    return oLinkMgr.GetLink(iLinkID)
Пример #13
0
def OnConnected(iSocketID):
    oLinkObject = CLinkObject(iSocketID)
    oLinkMgr = service.GetService("LinkManager")
    oLinkMgr.AddLink(oLinkObject)
    oLinkObject.VerifyLink()
Пример #14
0
def ConnectTimeout(iLinkID):
    timer.Unschedule("Connected_%s" % (iLinkID))
    logger.Info("connect timeout %s" % (iLinkID))
    oLinkMgr = service.GetService("LinkManager")
    oLinkObject = oLinkMgr.GetLink(iLinkID)
    oLinkObject.Disconnect("timeout")