Ejemplo n.º 1
0
    def pck_handler(self, pck):
        """
        解析数据包
        """
        p = Protocol(pck)
        pck_type = p.get_str()

        if pck_type == 'newrole':
            self.get_conn().x = p.get_int32()
            self.get_conn().y = p.get_int32()
            self.get_conn().name = p.get_str()
            self.get_conn().number = len(g_conn_pool)
            self.get_conn().my = None

            print(len(g_conn_pool))
            for i in g_conn_pool:
                print(i.__dir__())
                print('x : %s ' % i.x)
                print('y : %s ' % i.y)
                print('name : %s ' % i.name)
                print('number : %s ' % i.number)

            self.new_role()  # 告诉当前服务器的其他玩家,有新玩家加入
            self.other_role()  # 告诉新加入的玩家,当前服务器的其他玩家信息

        elif pck_type == 'move':
            self.get_conn().x = p.get_int32()
            self.get_conn().y = p.get_int32()
            self.move_role()
Ejemplo n.º 2
0
def pck_handler(pck):
    p = Protocol(pck)
    pck_type = p.get_str()

    if pck_type == 'playermove':  # 玩家移动的数据包
        x = p.get_int32()
        y = p.get_int32()
        name = p.get_str()
        for r in g_other_player:
            if r.name == name:
                r.x = x
                r.y = y
                break
    elif pck_type == 'newplayer':  # 新玩家数据包
        x = p.get_int32()
        y = p.get_int32()
        name = p.get_str()
        r = Role(x, y, name)
        g_other_player.append(r)
    elif pck_type == 'logout':  # 玩家掉线
        name = p.get_str()
        for r in g_other_player:
            if r.name == name:
                g_other_player.remove(r)
                break
Ejemplo n.º 3
0
def pck_handler(pck):
    p = Protocol(pck)
    try:
        pck_type = p.get_str()
        if pck_type == "games":
            try:
                return eval(p.get_str())
                # print(time.time())
                # print(messages[0])
            except Exception as e:
                print(e)
    except Exception as e:
        print(e)
Ejemplo n.º 4
0
    def pck_handler(self, pck):
        """
		解析数据包
		"""
        p = Protocol(pck)
        pck_type = p.get_int32()

        if pck_type == 1:
            self.get_conn().playerName = p.get_str()
            self.get_conn().x = p.get_int32()
            self.get_conn().y = p.get_int32()
            self.get_conn().charId = p.get_int32()
            self.new_role()  # 告诉当前服务器的其他玩家,有新玩家加入
            self.other_role()  # 告诉新加入的玩家,当前服务器的其他玩家信息

        elif pck_type == 0:
            self.get_conn().x = p.get_int32()
            self.get_conn().y = p.get_int32()
            self.move_role()
        elif pck_type == 3:

            self.get_conn().mouseX = p.get_int32()
            self.get_conn().mouseY = p.get_int32()
            self.get_conn().charId = p.get_int32()
            self.new_mouse()
        elif pck_type == 4:
            trigger = p.get_int32()
            charId = p.get_int32()
            self.new_animation(trigger, charId)
Ejemplo n.º 5
0
def pck_handler(pck):
    p = Protocol(pck)
    pck_type = p.get_str()

    if pck_type == 'playermove':  # 玩家移动的数据包
        x = p.get_int32()
        y = p.get_int32()
        name = p.get_str()
        for r in deploy.g_other_player:
            if r.name == name:
                r.x = x
                r.y = y
                break
    elif pck_type == 'newplayer':  # 新玩家数据包
        print('-----------------')
        print(pck)
        print(pck.decode('UTF-8'))
        print('-----------------')
        x = p.get_int32()
        y = p.get_int32()
        name = p.get_str()
        number = p.get_str()
        my = p.get_str()
        race = p.get_str()

        r = Role(x, y, name, number, my, race)
        deploy.g_other_player.append(r)
    elif pck_type == 'logout':  # 玩家掉线
        name = p.get_str()
        for r in deploy.g_other_player:
            if r.name == name:
                deploy.g_other_player.remove(r)
                break
Ejemplo n.º 6
0
    def pck_handler(self, pck):
        """
        解析数据包
        """
        p = Protocol(pck)
        pck_type = p.get_str()

        if pck_type == 'newrole':
            self.get_conn().x = p.get_int32()
            self.get_conn().y = p.get_int32()
            self.get_conn().name = p.get_str()
            self.new_role()  # 告诉当前服务器的其他玩家,有新玩家加入
            self.other_role()  # 告诉新加入的玩家,当前服务器的其他玩家信息

        elif pck_type == 'move':
            self.get_conn().x = p.get_int32()
            self.get_conn().y = p.get_int32()
            self.move_role()
Ejemplo n.º 7
0
    def pck_handler(self, pck):
        p = Protocol(pck)
        pck_type = p.get_int32()

        if pck_type == self.netPlayerMove:  # 玩家移动的数据包
            x = p.get_int32()
            y = p.get_int32()
            charId = p.get_int32()
            for r in self.charList:
                if r.charId == charId:
                    r.rect[0] = x
                    r.rect[1] = y
                    break
        elif pck_type == self.netPlayerNew:  # 新玩家数据包
            playerName = p.get_str()
            x = p.get_int32()
            y = p.get_int32()
            charId = p.get_int32()
            r = Model(self, charId)
            r.playerName = playerName
            self.charList.append(r)
        elif pck_type == self.netPlayerOff:  # 玩家掉线
            charId = p.get_int32()
            for r in self.charList:
                if r.charId == charId:
                    self.charList.remove(r)
                    break
        elif pck_type == self.netArmSwordNew:  # 手臂和剑状态更新

            mouseX = p.get_int32()
            mouseY = p.get_int32()
            charId = p.get_int32()
            for r in self.charList:
                if r.charId == charId:
                    r.oldMouseX = r.mouseX
                    r.oldMouseY = r.mouseY
                    r.mouseX = mouseX
                    r.mouseY = mouseY
                    #break
        elif pck_type == self.netAnimationNew:
            trigger = p.get_int32()
            charId = p.get_int32()
            self.charTrigger(trigger, charId)
        else:
            return
Ejemplo n.º 8
0
Archivo: server.py Proyecto: giftF/test
    def pck_handler(self, pck):
        """
        解析数据包
        """
        global usercount
        p = Protocol(pck)
        pck_type = p.get_str()
        users = eval(MR.get(room['users']))
        talk = MR.get(room['talk'])

        print(users)

        if pck_type == "newuser":
            self.get_conn().user['name'] = '%s%s' % (p.get_str(), usercount)
            usercount += 1
            self.get_conn().user['number'] = len(g_conn_pool)
            users.append(self.get_conn().user)
            talk += '欢迎%s加入游戏!\n' % self.get_conn().user['name']
            MR.set(room['users'], str(users))
            MR.set(room['talk'], str(talk))
        elif pck_type == "change":
            pass
        elif pck_type == "ready":
            print('收到一个ready请求')
            user_name = p.get_str()
            user_number = int(user_name[-1])
            user_isready = userreadydict[p.get_str()]

            # print(user_name)
            # print(user_isready)

            for r in g_conn_pool:
                if r == self.get_conn() and r.user['name'] == user_name:
                    for u in users:
                        if u['name'] == user_name:
                            u['isready'] = user_isready
                            MR.set(room['users'], str(users))
                            print('修改成功')
                            break
                    break
        elif pck_type == "talk":
            pass
        elif pck_type == "out":
            pass
        elif pck_type == "move":
            pass
        elif pck_type == "build":
            pass
        elif pck_type == "up":
            pass

        if pck_type == 'newrole':
            self.get_conn().x = p.get_int32()
            self.get_conn().y = p.get_int32()
            self.get_conn().name = p.get_str()
            self.get_conn().number = len(g_conn_pool)
            self.get_conn().my = None
            self.new_role()  # 告诉当前服务器的其他玩家,有新玩家加入
            self.other_role()  # 告诉新加入的玩家,当前服务器的其他玩家信息
        elif pck_type == 'move':
            self.get_conn().x = p.get_int32()
            self.get_conn().y = p.get_int32()
            self.move_role()