Exemple #1
0
def process_shoot_bullet(p, zipMsg):
    msgInfo = CS_GS_pb2.ShootBullet()
    msgInfo.ParseFromString(zipMsg.data)
    log.msg("recv msg:" + msgInfo.__str__())

    house = p.factory.roomDict.get(msgInfo.roomid)
    if house:
        house.shootBullet(msgInfo)
    else:
        msgInfo = CS_GS_pb2.ErrorMsg()
        msgInfo.errorid = error.ERR_SHOOT_BULLET
        p.transmitMessage(zipMsg, msgInfo)
Exemple #2
0
def process_take_damage(p, zipMsg):
    msgInfo = CS_GS_pb2.TakeDamage()
    msgInfo.ParseFromString(zipMsg.data)
    log.msg("recv msg:" + msgInfo.__str__())

    house = p.factory.roomDict.get(msgInfo.roomid)
    if house:
        house.takeDamage(msgInfo)
    else:
        msgInfo = CS_GS_pb2.ErrorMsg()
        msgInfo.errorid = error.ERR_MSG_ERROR
        p.transmitMessage(zipMsg, msgInfo)
Exemple #3
0
def process_transform_sync(p, zipMsg):
    msgInfo = CS_GS_pb2.TransformSync()
    msgInfo.ParseFromString(zipMsg.data)
    log.msg("recv msg:" + msgInfo.__str__())

    house = p.factory.roomDict.get(msgInfo.roomid)
    if house:
        house.transformSync(msgInfo)
    else:
        msgInfo = CS_GS_pb2.ErrorMsg()
        msgInfo.errorid = error.ERR_TRANSFORM_SYNC
        p.transmitMessage(zipMsg, msgInfo)
Exemple #4
0
    def handleMessage(self, msgID, Data):
        zipMsg = CS_GS_pb2.TransmitMsg()
        zipMsg.ParseFromString(Data)

        handler = self.REQUEST_HANDLERS.get(msgID)
        if handler:
            handler(self, zipMsg)
Exemple #5
0
 def connectionMade(self):
     msgInfo = CS_GS_pb2.AskRegister()
     msgInfo.state = 0
     for key in self.REQUEST_HANDLERS:
         msgInfo.msgList.append(key)
     self.sendMessage(msgInfo)
     log.msg('Center->Gate Start!', self.transport.getPeer())
Exemple #6
0
 def broadcastState(self, member, entityType):
     msgInfo = CS_GS_pb2.StateSync()
     msgInfo.entity.entitytype = entityType
     msgInfo.entity.entityid = member.entityID
     msgInfo.entity.health = member.health
     msgInfo.entity.healthmax = member.healthMax
     msgInfo.entity.score = member.score
     self.broadcastMsg(msgInfo)
Exemple #7
0
    def handleMessage(self, proto, msgID, Data):
        transmitMsg = CS_GS_pb2.TransmitMsg()
        transmitMsg.ParseFromString(Data)
        mail = transmitMsg.mail
        bytesDdata = transmitMsg.data

        user = ClinetInstance.users.get(mail)
        if user:
            packData = user.packData(msgID, bytesDdata)
            user.sendBytes(packData)
        else:
            transmitMsg = CS_GS_pb2.TransmitMsg()
            transmitMsg.mail = mail
            transmitMsg.msgid = CS_GS_pb2.GS2CS_Error
            errorMsg = CS_GS_pb2.ErrorMsg()
            errorMsg.errorid = error.ERR_USER_LOGOUT
            transmitMsg.data = errorMsg.SerializeToString()
            proto.sendMessage(transmitMsg)
            print("cant find user:", mail, msgID)
Exemple #8
0
def process_user_info(p, zipMsg):
    msgInfo = CS_GS_pb2.UserInfo()
    msgInfo.ParseFromString(zipMsg.data)
    log.msg("recv msg:" + msgInfo.__str__())

    userMail = zipMsg.mail
    print(userMail)
    msgInfo.name = "hahaha"

    p.transmitMessage(zipMsg, msgInfo)
Exemple #9
0
 def broadcastMsg(self, msgInfo):
     msgInfo.roomid = self.roomID
     zipMsg = CS_GS_pb2.TransmitMsg()
     zipMsg.msgid = msgInfo.msgid
     for key, value in self.members.items():
         if not value.active:
             continue
         zipMsg.mail = key
         msgInfo.mail = key
         self.gateProto.transmitMessage(zipMsg, msgInfo)
Exemple #10
0
    def handleMessage(self, proto, msgID, Data):
        for key, value in CenterInstance.centerServers.items():
            centerProto, msgList = value
            if msgID in msgList:
                transmitMsg = CS_GS_pb2.TransmitMsg()
                transmitMsg.mail = proto.userInfo.get("mail")
                transmitMsg.msgid = msgID
                transmitMsg.data = Data
                return centerProto.sendMessage(transmitMsg)

        print("handle not found:%i" % msgID)
Exemple #11
0
def process_start_match(p, zipMsg):
    msgInfo = CS_GS_pb2.StartMatch()
    msgInfo.ParseFromString(zipMsg.data)
    log.msg("recv msg:" + msgInfo.__str__())

    mail = msgInfo.mail
    waiters = p.factory.matchList
    if mail not in waiters:
        p.factory.matchList.append(mail)
        msgInfo.result = 1
    else:
        msgInfo.result = 0
    p.transmitMessage(zipMsg, msgInfo)
Exemple #12
0
 def addPlayers(self, players):
     for _, value in enumerate(players):
         userInfo = user.getUser(value)
         if userInfo is None:
             continue
         userInfo["roomid"] = self.roomID
         user.updateUser(userInfo, ["roomid"])
         self.members[value] = player.Player(value, userInfo["name"])
         zipMsg = CS_GS_pb2.TransmitMsg()
         zipMsg.mail = value
         msgInfo = CS_GS_pb2.EnterRoom()
         msgInfo.mail = value
         msgInfo.name = userInfo["name"]
         msgInfo.roomid = self.roomID
         msgInfo.mapid = str(self.mapID)
         msgInfo.mapdata = self.mapData
         msgInfo.entity.entitytype = CS_GS_pb2.Entity_Active
         msgInfo.entity.entityid = value
         msgInfo.entity.health = self.members[value].health
         msgInfo.entity.healthmax = self.members[value].healthMax
         msgInfo.entity.score = self.members[value].score
         self.gateProto.transmitMessage(zipMsg, msgInfo)
Exemple #13
0
def process_error_msg(p, zipMsg):
    msg = CS_GS_pb2.ErrorMsg()
    msg.ParseFromString(zipMsg.data)
    log.msg("recv msg:" + msg.__str__())

    if msg.errorid == error.ERR_CENTER_ADDRESS:
        print("错误的中心服务器地址")
    elif msg.errorid == error.ERR_USER_LOGOUT:
        mail = zipMsg.mail
        userInfo = user.getUser(mail)
        if userInfo:
            roomId = userInfo.get("roomid")
            house = p.factory.roomDict.get(roomId)
            if house:
                house.deletePlayer(mail)
Exemple #14
0
    def update(self, timeInterval):
        msgInfo = CS_GS_pb2.TransformSync()
        for key, value in self.members.items():
            if not value.active:
                continue
            value.update(timeInterval)

            transformInfo = msgInfo.transforminfo.add()
            transformInfo.mail = key
            transformInfo.speed = value.speed
            for key, pos in enumerate(value.position):
                transformInfo.position.append(pos)
            for key, rot in enumerate(value.rotation):
                transformInfo.rotation.append(rot)

        self.broadcastMsg(msgInfo)
Exemple #15
0
def process_register_result(p, zipMsg):
    msgInfo = CS_GS_pb2.AskRegister()
    msgInfo.ParseFromString(zipMsg.data)
    log.msg("recv msg:" + msgInfo.__str__())

    if msgInfo.state == 1:
        p.factory.gateProto = p
        log.msg("Center Register Success!")

        if p.factory.matchTask:
            p.factory.matchTask.stop()
        p.factory.matchTask = task.LoopingCall(match.handleWaiters)
        p.factory.matchTask.start(const.MatchTimeInterval)

        if p.factory.roomTask:
            p.factory.roomTask.stop()
        p.factory.roomTask = task.LoopingCall(p.factory.update)
        p.factory.roomTask.start(const.UpdateTimeInterval)
    else:
        log.msg("Center Register Failed!")