ZH-CN/addAccount

From Multi Theft Auto: Wiki
Jump to navigation Jump to search

此函数用于将帐户添加到当前服务器的已注册帐户列表中.

语法

account addAccount ( string name, string pass [, bool allowCaseVariations = false ] )

OOP 语法 什么是OOP?

方法: 此函数是Account类下面的静态函数.(...)
变量: .Account.add

必填参数

  • name: 您希望创建的帐户的名称,这通常是玩家的名称.
  • pass: 为以后登录此帐户设置的密码.

选填参数

  • allowCaseVariations: 用户名是否区分大小写(如果设置为true,则用户名“Bob”和“bob”将引用不同的帐户)

返回值

成功时创建一个账户account,如果账户已存在或发生错误则返回“false”.

限制

  • 账户:
    • 最小帐户名长度为1个字符.
    • 如果allowCaseVariations为“true”,则帐户名区分大小写.
    • 帐户名不能等于“*****”
  • 密码:
    • 最小帐户密码长度为1个字符.
    • 在版本1.5.4-11138之前,帐户密码的最大长度为30个字符。目前没有上限.
    • 帐户密码不能等于“*****”

案例

案例 1: 这使玩家可以在聊天窗口中输入/register<account>在服务器上注册.

function registerPlayer ( source, commandName, password )
	-- 检查密码字段是否为空(如果没有输入,则为空)
	if ( password ~= "" and password ~= nil ) then
		--尝试添加帐户,并将其值保存在var中
		local accountAdded = addAccount( getPlayerName(source), password )
		if ( accountAdded ) then
			--  告诉用户账号注册完成了
			outputChatBox ( "谢谢 " .. getPlayerName(source) .. ", 您现在已注册,可以使用/login登录", source )
		else
			-- 创建帐户时出错了,请告诉用户
			outputChatBox ( "创建帐户时出错,请与服务器管理员联系", source )
		end
	else
		--语法错误,请告诉用户正确的语法.
		outputChatBox ( "创建帐户时出错,请输入正确语法的指令:/register <password>", source )
	end
end
addCommandHandler ( "register", registerPlayer ) -- 添加命令处理程序

This code differs by allowing the user to change their username that they wish to use.

Example 2: This enables players to register on your server by using /register <username> <password> in the chat window.

function registerPlayer ( source, commandName, username, password )
        if(password ~= "" and password ~= nil and username ~= "" and username ~= nil) then
                local accountAdded = addAccount(username,password)
                if(accountAdded) then
                        outputChatBox("Thank you " .. getPlayerName(source) .. ", you're now registed, you can login with /login",source)
                else
                        outputChatBox("Error creating account, contact the server admin.",source)
                end
        else
                outputChatBox("Error creating account, correct syntax: /register <nick> <pass>",source)
        end
end
addCommandHandler ( "register", registerPlayer ) -- add the command handler

Example 3: This code differs again so the user can only register once /register <username> <password>.

bRegisteredOnce = {}

function registerPlayer ( source, commandName, username, password )
        if(password ~= "" and password ~= nil and username ~= "" and username ~= nil and not bRegisteredOnce[source]) then
                local accountAdded = addAccount(username,password)
                if(accountAdded) then
                        outputChatBox("Thank you " .. getPlayerName(source) .. ", you're now registed, you can login with /login",source)
                        bRegisteredOnce[source] = true
                else
                        outputChatBox("Error creating account, contact the server admin.",source)
                end
        else
                if bRegisteredOnce[source] == true then
                    outputChatBox("You already registered on this server!",source)
                else
                    outputChatBox("Error creating account, correct syntax: /register <nick> <pass>",source)
                end
        end
end

See Also