找回密码
 点一下
查看: 1950|回复: 3

制作拥有savecode功能地图所需用到的效检程序

[复制链接]
发表于 2006-5-29 01:24:17 | 显示全部楼层 |阅读模式
很多地图都有savecode了吧。
savecode是什么?OK,不用解释了吧。
好吧,什么crc效检之类的东西都太复杂了,我脑袋不灵通,暂时想出这么一个简单的办法效检字符串。

什么?为什么要效检字符串?
好吧,如果玩家密码输错了怎么办?你不会一个个去检查吧,要是玩家乱改代码取巧怎么办?好吧,玩家猜对了你也没则。。


OK,效检字符串的原代码如下,相信还是有几分用处的:

[jass]
constant function GetCharacterSet takes nothing returns string
    return " !\"#$%%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
endfunction

function AsciiCharToInteger takes string char returns integer
    local string u = SubString(char, 0, 1)
    local string c
    local integer i = 0
    if u == "" or u == null then
        return 0
    elseif u == "\b" then // BackSpace?
        return 8
    elseif u == "\t" then // Horizontal Tab?
        return 9
    elseif u == "\n" then // Newline?
        return 10
    elseif u == "\f" then // Form feed?
        return 12
    elseif u == "\r" then // Carriage return
        return 13
    endif
    loop
        set c = SubString(GetCharacterSet(), i, i + 1)
        exitwhen c == ""
        if c == u then
            return i + 32
        endif
        set i = i + 1
    endloop
    return 0
endfunction

//获得效检码
function GetPassCodeCheckNumber takes string passcode returns integer
    local integer index = 1
    local integer check = 0
    if passcode == "" and passcode == null then
        return 0
    endif
    loop
        exitwhen index > StringLength(passcode)
       //数学算法,总之怎么乱怎么算老……
        set check = check + AsciiCharToInteger(SubString(passcode,index-1,index))/index*(index+2)
        set index = index + 1
    endloop
    if StringLength(I2S(check)) > 3 then
        return S2I(SubString(I2S(check),StringLength(I2S(check))-3,StringLength(I2S(check))))
    endif
    return check
endfunction

//效对代码
function CheckPassCode takes string passcode ,integer checknumber returns boolean
    return GetPassCodeCheckNumber(passcode) == checknumber
endfunction

[/jass]

这种效对算法虽然不是十分严谨,但也有九分严谨了……至于数学算法,爱怎么算就怎么算吧。。。。

以下是演示老……

[jass]
function RandomChar takes nothing returns string
    local integer a = GetRandomInt(1, StringLength(GetCharacterSet()))
    return SubString(GetCharacterSet(),a-1,a)
endfunction

function RandomString takes integer length returns string
    local integer index = 1
    local string str = ""
    if length == 0 or length > 1000 then
        return ""
    endif
    loop
        exitwhen index > length
        set str = str + RandomChar()
        set index = index + 1
    endloop
    return str
endfunction[/jass]
这两个函数是产生随机字符串用的,主要是测试用。

[ 本帖最后由 蚊子叮 于 2006-5-29 01:26 编辑 ]
发表于 2006-5-29 01:29:05 | 显示全部楼层
呵呵,和我一样半夜睡不着翻论坛啊?

看的头晕老 5555恩恩,仍然继续推荐中文字符哈哈
回复

使用道具 举报

 楼主| 发表于 2006-5-29 01:38:03 | 显示全部楼层
恩恩,期待第一个做出中文字符savecode的尸体出现。
回复

使用道具 举报

发表于 2006-5-29 01:40:00 | 显示全部楼层
555 我不能做,我已经熬夜4天了,再下去真成老尸体了.暗暗

于是去测试这个演示去了
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 点一下

本版积分规则

Archiver|移动端|小黑屋|地精研究院

GMT+8, 2024-5-4 20:01 , Processed in 0.099823 second(s), 19 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表