Esempio n. 1
0
def OnLoginRequest(client, address, gameLogic):
    Log("[%s] : [ %s:%i ] request login." % (ctime(), address[0], address[1]))
    data = ReceiveDataFromClient(client, address)
    accountData = TransferProtocal_pb2.Account()
    accountData.ParseFromString(data)
    res = gameLogic.LogIn(accountData.account, accountData.password)
    # SendReplyCode(client, TransferProtocal_pb2.ResultType.LOGIN_RES)
    # Log("[%s] : Send to [ %s:%i ] . Msg : reply code[loginRes]." % (ctime(), address[0], address[1]))
    Reply = TransferProtocal_pb2.LoginRes()
    if res[0]:
        Reply.hasSucceed = True
    else:
        Reply.hasSucceed = False
        if res[1] == 1:
            Reply.error = TransferProtocal_pb2.LoginRes.INVALIDATED_PASSWORD
        else:
            Reply.error = TransferProtocal_pb2.LoginRes.INVALIDATED_ACCOUNT
    SendDataToClient(client, address, Reply.SerializeToString())
    client.recv(BufferSize)
Esempio n. 2
0
def testLogin():
    tcpCliSock = socket(AF_INET, SOCK_STREAM)
    tcpCliSock.connect(ADDR)
    request = TransferProtocal_pb2.RequestType()
    request.request = TransferProtocal_pb2.RequestType.LOGIN_REQ

    data = request.SerializeToString()
    sendDataToServer(tcpCliSock, ADDR, data)

    request = TransferProtocal_pb2.Account()
    request.account = "hrhtr4"
    request.password = "******"

    sendDataToServer(tcpCliSock, ADDR, request.SerializeToString())

    data = receiveDataFromServer(tcpCliSock, ADDR)
    tcpCliSock.send("OK".encode())
    result = TransferProtocal_pb2.LoginRes()
    result.ParseFromString(data)
    #print(str(result.hasSucceed),str(result.error))

    tcpCliSock.close()