Update libcredit_mobile.lua
This commit is contained in:
		
							parent
							
								
									3ae183b105
								
							
						
					
					
						commit
						df88bcf6f8
					
				| 
						 | 
				
			
			@ -31,6 +31,41 @@ local function sendRequestAndWaitForReply(messageTable, replyHandler, timeout)
 | 
			
		|||
    return replyReceived
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function M.createAccount(username, associatedDevice, callback)
 | 
			
		||||
    if type(username) ~= "string" or #username == 0 then
 | 
			
		||||
        error("Username must be a non-empty string.", 2)
 | 
			
		||||
    end
 | 
			
		||||
    if type(callback) ~= "function" then
 | 
			
		||||
        error("Callback must be a function.", 2)
 | 
			
		||||
    end
 | 
			
		||||
    if associatedDevice and type(associatedDevice) ~= "number" then
 | 
			
		||||
        error("Associated device must be a number if provided.", 2)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    local message = {
 | 
			
		||||
        type = "createAccount",
 | 
			
		||||
        user = username
 | 
			
		||||
    }
 | 
			
		||||
    if associatedDevice then
 | 
			
		||||
        message.associatedDevice = associatedDevice
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    return sendRequestAndWaitForReply(message, function(reply)
 | 
			
		||||
        if reply.type == "accountCreationConfirmation" and reply.user == username then
 | 
			
		||||
            if reply.status == "success" then
 | 
			
		||||
                print("Account '" .. username .. "' created successfully. New credit: " .. tostring(reply.newCredit))
 | 
			
		||||
                callback(true, reply.newCredit)
 | 
			
		||||
            else
 | 
			
		||||
                print("Account creation failed for '" .. username .. "'. Reason: " .. tostring(reply.reason))
 | 
			
		||||
                callback(false, reply.reason)
 | 
			
		||||
            end
 | 
			
		||||
        else
 | 
			
		||||
            print("Unexpected reply for createAccount request: " .. textutils.serialiseJSON(reply))
 | 
			
		||||
            callback(false, "unexpected_reply")
 | 
			
		||||
        end
 | 
			
		||||
    end)
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function M.getCredit(username, callback)
 | 
			
		||||
    local message = {
 | 
			
		||||
        type = "getCredit",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user