Ejemplo n.º 1
0
def sendFile(ip, filepath):
    d = {
        feiqcore.cmd: feiqcore.sendfile,
        feiqcore.filename: filepath,
        feiqcore.uuid: feiqnet.uuid,
        feiqcore.name: feiqnet.name
    }

    feiqnet.sendDict(d, ip)
Ejemplo n.º 2
0
def sendMsg(ip, msg):
    d = {
        feiqcore.cmd: feiqcore.msg,
        feiqcore.msg: msg,
        feiqcore.uuid: feiqnet.uuid,
        feiqcore.name: feiqnet.name
    }

    feiqnet.sendDict(d, ip)
Ejemplo n.º 3
0
def sendDir(ip, dirpath):
    d = {
        feiqcore.cmd: feiqcore.senddir,
        feiqcore.filename: dirpath,
        feiqcore.uuid: feiqnet.uuid,
        feiqcore.name: feiqnet.name
    }

    feiqnet.sendDict(d, ip)
Ejemplo n.º 4
0
def handleNetwork(recvPack, ip):

    if recvPack[feiqcore.cmd] == feiqcore.sendfile:
        d = {
            feiqcore.cmd: feiqcore.sendfileack,
            feiqcore.filename: recvPack[feiqcore.filename],
            feiqcore.uuid: feiqnet.uuid,
            feiqcore.name: feiqnet.name
        }

        feiqnet.sendDict(d, ip)

    elif recvPack[feiqcore.cmd] == feiqcore.sendfileack:
        # 创建线程,发送文件
        thread = Thread(target=feiqfile.sendFileThread,
                        args=(recvPack[feiqcore.filename], ip))
        thread.start()

    elif recvPack[feiqcore.cmd] == feiqcore.online:
        if recvPack[feiqcore.uuid] == feiqnet.uuid:
            return True
        feiquser.addUser(recvPack[feiqcore.name], recvPack[feiqcore.uuid], ip)
        # 回应我也在线
        feiqnet.onlineack(ip)
        print('  user: %s %s %s online' %
              (recvPack[feiqcore.name], recvPack[feiqcore.uuid], ip))

    elif recvPack[feiqcore.cmd] == feiqcore.onlineack:
        feiquser.addUser(recvPack[feiqcore.name], recvPack[feiqcore.uuid], ip)

    elif recvPack[feiqcore.cmd] == feiqcore.offline:
        if recvPack[feiqcore.uuid] == feiqnet.uuid:
            return False
        feiquser.removeUser(recvPack[feiqcore.name], recvPack[feiqcore.uuid],
                            ip)

    elif recvPack[feiqcore.cmd] == feiqcore.msg:
        if recvPack[feiqcore.uuid] == feiqnet.uuid:
            return True
        msg = recvPack[feiqcore.msg]
        print(('%s (%s) say : %s') % (recvPack[feiqcore.name], ip, msg))

    elif recvPack[feiqcore.cmd] == feiqcore.setname:
        if recvPack[feiqcore.uuid] == feiqnet.uuid:
            return True
        feiquser.changeName(recvPack[feiqcore.uuid], recvPack[feiqcore.name])

    return True