예제 #1
0
 def CheckTimer(self):
     timecontrol.Remove_Call_Out("loginrecord")
     pubdefines.FormatPrint("历史排行榜第一 %s" % self.m_Data.get("score1", 0))
     pubdefines.FormatPrint("历史排行榜第二 %s" % self.m_Data.get("score2", 0))
     pubdefines.FormatPrint("历史排行榜第三 %s" % self.m_Data.get("score3", 0))
     timecontrol.Call_Out(pubcore.Functor(self.CheckTimer), 300,
                          "loginrecord")
예제 #2
0
 def Start(self):
     if not self.m_oSocket:
         return
     pubdefines.FormatPrint("等待客户端链接")
     while not self.m_bClose:
         sockobj, address = self.m_oSocket.accept()
         pubdefines.FormatPrint("客户端链接")
         iUID = self.NewUID()
         ip, port = address
         self.NewItem(iUID, sockobj, ip, port)
예제 #3
0
    def CalPos(self, oClient, dData):
        self.begin = dData["BeginCountDown"]
        self.restart = dData["Restart"]
        self.isgameover = dData["isgameover"]
        self.pscore = dData["pscore"]

        if self.restart:
            pubdefines.FormatPrint("restart")
            self.CountNum = 120
            self.isrestart = True

        if self.begin:
            #pubdefines.FormatPrint("开始传输数据")
            dReturn = {
                "action": "show",
                "Count": self.CountNum,
                "timeout": self.timeout,
                "isrestart": self.isrestart,
                "score1": self.m_Data["score1"],
                "score2": self.m_Data["score2"],
                "score3": self.m_Data["score3"]
            }
            oClient.Send(dReturn)
            if self.restart:
                self.isrestart = True
            if self.restart == False:
                self.isrestart = False

            if self.isCount:
                pubdefines.FormatPrint("开始Timer")
                t = threading.Timer(1.0, self.CountDown)
                t.start()

            self.isCount = False

            if self.pscore != -1:
                if self.pscore >= self.score1:
                    self.m_Data["score3"] = self.score2
                    self.m_Data["score2"] = self.score1
                    self.m_Data["score1"] = self.pscore
                    self.Save()
                    self.pscore = -1
                elif self.pscore >= self.score2:
                    self.m_Data["score3"] = self.score2
                    self.m_Data["score2"] = self.pscore
                    self.Save()
                    self.pscore = -1
                elif self.pscore >= self.score3:
                    self.m_Data["score3"] = self.pscore
                    self.Save()
                    self.pscore = -1
                else:
                    self.pscore = -1
예제 #4
0
 def OnCommand(self, oClient, dData):
     sAction = dData.get("action", "")
     if not sAction or not sAction in self.m_CommandDict:
         pubdefines.FormatPrint("未定义客户端的调用%s" % sAction)
         return 
     sImport, sFunc = self.m_CommandDict[sAction]
     oModule = __import__(sImport)
     oFunc = getattr(oModule, sFunc, None)
     if not oFunc:
         pubdefines.FormatPrint("客户端触发%s行为,%s模块未找到接口%s" % (sAction, sImport, sFunc))
         return
     oFunc(oClient, dData)
예제 #5
0
    def CountDown(self):

        #pubdefines.FormatPrint("CountDown")
        self.CountNum = self.CountNum - 1
        global t
        t = threading.Timer(1.0, self.CountDown)
        t.start()
        if self.CountNum == 0:  # 计时停止时间
            pubdefines.FormatPrint("timeout")
            t.cancel()
            self.timeout = True
        if self.isgameover:  # 游戏结束
            pubdefines.FormatPrint("gameover")
            t.cancel()
예제 #6
0
파일: __init__.py 프로젝트: sadie6/Test4-5
def Call_Out(oFunc, iDelay, sKey):
    if not iDelay:
        pubdefines.FormatPrint("回调时间不能为0")
        return
    if not oFunc:
        return
    pubglobalmanager.CallManagerFunc(defines.TIME_CONTRL_MANAGER, "Register",
                                     oFunc, iDelay, sKey)
예제 #7
0
 def InitManger(self):
     try:
         pubdefines.FormatPrint("服务器监听开始")
         self.m_oSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
         self.m_oSocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
         self.m_oSocket.bind(("127.0.0.1", 12080))
         self.m_oSocket.listen(5)
     except:
         self.m_oSocket = None
         pubdefines.PythonError()
예제 #8
0
 def TrasnData(self, obj):
     if isinstance(obj, dict):
         res = {}
         for key, value in obj.iteritems():
             tempkey = self.TrasnData(key)
             tempvalue = self.TrasnData(value)
             res[tempkey] = tempvalue
         pubdefines.FormatPrint("dict")
         return res
     elif isinstance(obj, list):
         res = []
         for value in obj:
             res.append(self.TrasnData(value))
         pubdefines.FormatPrint("list")
         return res
     elif isinstance(obj, unicode):
         pubdefines.FormatPrint("unicode")
         return obj.encode("utf-8")
     else:
         pubdefines.FormatPrint("other")
         return obj
예제 #9
0
 def CheckTimer(self):
     timecontrol.Remove_Call_Out("loginrecord")
     pubdefines.FormatPrint("定时器统计:目前总连接记录 %s" % self.m_Data.get("total", 0))
     timecontrol.Call_Out(pubcore.Functor(self.CheckTimer), 300, "loginrecord")
예제 #10
0
def InitLogDir():
    try:
        os.mkdir("log")
    except:
        pubdefines.FormatPrint("log目录已经存在")
예제 #11
0
def StartGame():
    pubdefines.FormatPrint("启动服务器")
    LoadServerConsole()
    clientsocket.Start()
예제 #12
0
 def CountDown():
     for i in range(11):
         pubdefines.FormatPrint(11 - i)
         time.sleep(1)