Exemple #1
0
def testRegister():
    tcpCliSock = socket(AF_INET, SOCK_STREAM)
    tcpCliSock.connect(ADDR)
    request = TransferProtocal_pb2.RequestType()
    request.request = TransferProtocal_pb2.RequestType.REGISTER_REQ

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

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

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

    # data = tcpCliSock.recv(BufferSize)
    # ReplyCode = TransferProtocal_pb2.ResultType()
    # ReplyCode.ParseFromString(data)
    #
    # if ReplyCode.result == TransferProtocal_pb2.ResultType.REGISTER_RES:
    data = receiveDataFromServer(tcpCliSock, ADDR)
    tcpCliSock.send("OK".encode())
    result = TransferProtocal_pb2.RegisterRes()
    result.ParseFromString(data)
    #print(str(result.hasSucceed),str(result.error))

    tcpCliSock.close()
Exemple #2
0
def OnRegisterRequest(client, address, gameLogic):
    Log("[%s] : [ %s:%i ] request register." %
        (ctime(), address[0], address[1]))
    data = ReceiveDataFromClient(client, address)
    accountData = TransferProtocal_pb2.Account()
    accountData.ParseFromString(data)
    res = gameLogic.Register(accountData.account, accountData.password)
    # #SendReplyCode(client, TransferProtocal_pb2.ResultType.REGISTER_RES)
    # #Log("[%s] : Send to [ %s:%i ] . Msg : reply code[registerRes]." % (ctime(), address[0], address[1]))
    Reply = TransferProtocal_pb2.RegisterRes()
    if res:
        Reply.hasSucceed = True
    else:
        Reply.hasSucceed = False
        Reply.error = TransferProtocal_pb2.RegisterRes.USER_EXIT
    SendDataToClient(client, address, Reply.SerializeToString())
    client.recv(BufferSize)
# test

from Protocal.generate import TransferProtocal_pb2

request = TransferProtocal_pb2.RequestType()
request.request = TransferProtocal_pb2.RequestType.REGISTER_REQ
data = request.SerializeToString()

result = TransferProtocal_pb2.ResultType()
result.result = TransferProtocal_pb2.ResultType.REGISTER_RES

account = TransferProtocal_pb2.Account()
account.account = "dfsefefsf"
account.password = "******"
account.data = "gdrlgrjmijgg的距离高考家里人".encode()

registerRes = TransferProtocal_pb2.RegisterRes()
registerRes.hasSucceed = True
registerRes.error = TransferProtocal_pb2.RegisterRes.INVALIDATED_ACCOUNT

archiveOp = TransferProtocal_pb2.ArchiveOpRes()
archiveOp.hasSucceed = False
archiveOp.operation = TransferProtocal_pb2.ArchiveOpRes.ADD
archiveOp.data = "dijgim规模i然后554632".encode()