Esempio n. 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()
Esempio n. 2
0
def RequestProcess(client, address, DBHandlerIndex, HandlerPool):
    try:
        gameLogic = GameBusicness(HandlerPool[DBHandlerIndex])

        # 设置超时时间
        client.settimeout(MaxDelayTime)
        # 接收数据的大小
        buf = client.recv(BufferSize)

        request = TransferProtocal_pb2.RequestType()
        request.ParseFromString(buf.strip(b' '))

        service = ServiceAvailable[request.request]
        service(client, address, gameLogic)
    # 超时后退出
    except socket.timeout:
        Log('[%s] : [ %s:%i ] time out' % (ctime(), address[0], address[1]))
    except ConnectionResetError:
        Log('[%s] : [ %s:%i ] actively disconnected' %
            (ctime(), address[0], address[1]))
    except Exception:
        Log('[%s] : [ %s:%i ] unknow error happened' %
            (ctime(), address[0], address[1]))
    finally:
        # 关闭与客户端的连接
        client.close()
Esempio n. 3
0
def OnSaveArchiveRequest(client, address, gameLogic):
    Log("[%s] : [ %s:%i ] request saveArchive." %
        (ctime(), address[0], address[1]))
    data = ReceiveDataFromClient(client, address)
    accountData = TransferProtocal_pb2.Account()
    accountData.ParseFromString(data)
    res = gameLogic.SaveArchive(accountData.account, accountData.data)
    # SendReplyCode(client, TransferProtocal_pb2.ResultType.SAVE_ARCHIVE_RES)
    # Log("[%s] : Send to [ %s:%i ] . Msg : reply code[saveArchiveRes]." % (ctime(), address[0], address[1]))
    Reply = TransferProtocal_pb2.ArchiveOpRes()
    Reply.operation = TransferProtocal_pb2.ArchiveOpRes.ADD
    if res:
        Reply.hasSucceed = True
    else:
        Reply.hasSucceed = False
    SendDataToClient(client, address, Reply.SerializeToString())
    client.recv(BufferSize)
Esempio n. 4
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)
Esempio n. 5
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. 6
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()
Esempio n. 7
0
def testDeletaArchive():
    tcpCliSock = socket(AF_INET, SOCK_STREAM)
    tcpCliSock.connect(ADDR)
    request = TransferProtocal_pb2.RequestType()
    request.request = TransferProtocal_pb2.RequestType.DELETE_ARCHIVE_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.ArchiveOpRes()
    result.ParseFromString(data)
    ##print(str(result.hasSucceed), str(result.operation))

    tcpCliSock.close()
Esempio n. 8
0
# 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()
Esempio n. 9
0
def SendReplyCode(client, resType):
    Reply = TransferProtocal_pb2.ResultType()
    Reply.result = resType
    client.send(Reply.SerializeToString())