Changeset 3234

Show
Ignore:
Timestamp:
01/24/10 01:19:20 (7 months ago)
Author:
ghoulsblade
Message:
two new macro helpers : MacroCmd_WaitForListener MacroCmd_WaitForText , fixed text entry gump for old pol crafting system, IsTargetModeActive check in CompleteTargetMode to avoid illegal messages if used directly by scripts, new shard config gAutoSelectServerIndex for shards with multiple subservers
Location:
trunk/lua
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • trunk/lua/lib.cursor.lua

    r3210 r3234  
    141141 
    142142function CompleteTargetMode (hitobject,maxrange) -- maxrange=nil 
     143        if (not IsTargetModeActive()) then return end 
    143144    if (not hitobject) then 
    144145        MainMousePick() 
  • trunk/lua/lib.macrolist.lua

    r3218 r3234  
    815815end 
    816816 
    817 -- waits until a given text appears, list = {text=returnvalue, text=returnvalue, ...} 
     817-- call from a job! (see job.create) 
     818-- returns key(from textlist),plaintext,textdata      or nil if timeout 
     819function MacroCmd_WaitForText (textlist,timeout_delay)  
     820        return MacroCmd_WaitForListener("Hook_Text",function (name,plaintext,serial,data)   
     821                        for k,text in pairs(textlist) do if (string.find(plaintext,text)) then return k,plaintext,data end end  
     822                end,timeout_delay or 9000)  
     823end 
     824 
     825-- call from a job! (see job.create) 
     826-- pauses the current job until a listener with listenername is notified and fun returns true for the listener, or until a timeout 
     827-- returns the complete resultset from fun, or nil if timeout 
     828function MacroCmd_WaitForListener (listenername,fun,timeout_delay) 
     829        timeout_delay = timeout_delay or 9000 
     830        local timeout = gMyTicks+timeout_delay 
     831        local jobid = job.running_id() assert(jobid) 
     832        local done = false 
     833        local res 
     834        RegisterListener(listenername,function (...)  
     835                if (done or gMyTicks > timeout) then return true end 
     836                res = {fun(...)} 
     837                if (res[1]) then done = true job.wakeup(jobid) return true end 
     838                end) 
     839        job.wait(timeout_delay) 
     840        done = true 
     841        if (res) then return unpack(res) end 
     842end 
     843 
     844 
     845-- waits until a given text appears, list = {text=returnvalue, text=returnvalue, ...} .... see also MacroCmd_WaitForText (might be better/faster) 
    818846function MacroJournal_WaitForText   (list,timeout) 
    819847    if not list then return end 
  • trunk/lua/lib.mainmenu.lua

    r3218 r3234  
    181181        return 
    182182    end 
     183         
     184        if (gAutoSelectServerIndex) then MainMenu_SendServer(gAutoSelectServerIndex) return end 
    183185     
    184186    -- show serverlist 
  • trunk/lua/net/net.login.lua

    r3095 r3234  
    2929 
    3030        serverlist.servers = {} 
     31        serverlist.servers_by_index = {} 
    3132        gSubServerNamesByID = {} 
    3233        for i = 0,serverlist.iServerNumber - 1 do 
     
    3839                server.ip = input:PopNetUint32() 
    3940                serverlist.servers[i] = server 
     41                serverlist.servers_by_index[server.index] = server 
    4042                gSubServerNamesByID[server.index] = server.name 
    4143                 
  • trunk/lua/net/net.objectpicker.lua

    r3092 r3234  
    7676 
    7777-- response to 0xAB 
     78 
    7879function Send_String_Query_Response (id,mytype,myidx,response) -- 0xAC 
    7980        local responselen = string.len(response) 
    8081        local out = GetSendFIFO() 
     82         
    8183        out:PushNetUint8(kPacket_String_Response) 
    82         out:PushNetUint16(responselen+3+1+1+4+2+1) 
     84        out:PushNetUint16(responselen+1 +3 +1+1 +4+2+1) 
    8385        out:PushNetUint32(id) 
    8486        out:PushNetUint8(mytype) 
    8587        out:PushNetUint8(myidx) 
     88        out:PushNetUint8(1) -- unknown 
    8689        out:PushNetUint8(0) -- unknown 
    87         out:PushNetUint8(0) -- unknown 
    88         out:PushNetUint8(0) -- unknown 
     90        out:PushNetUint8(responselen+1) -- unknown 
    8991        out:PushFilledString(response,responselen) 
     92        out:PushNetUint8(0) -- zero term 
     93                                  
     94--~ 0000   AC 00 0E 01 40 05 18 00  00 01 00 02 32 00         ....@.......2.        
     95           --~ c] [len] [----id---] ty  id u1 u2 u3 [text] 
     96          
     97       --~ ac 00 0f 01 40 05 18 00  00 00 00 00 01 31 00      |....@........1.| 
     98            
     99        print("###############################") 
     100        print("rawstr:#"..response.."# len="..responselen) 
     101        print(FIFOHexDump(out)) 
     102        print("###############################") 
     103         
    90104        out:SendPacket() 
     105        print("Send_String_Query_Response",hex(id),hex(mytype),hex(myidx)) 
    91106        -- doesn't seemt to work yet =( 
    92107end 
     
    116131         
    117132        data.datalenleft = size-1-2-4-1-1-2-data.textlen-1-1-4-1 
     133        if (data.datalenleft > 0) then data.text2head = input:PopNetUint8() data.datalenleft = data.datalenleft - 1 end 
    118134        data.text2              = (data.datalenleft > 0) and input:PopFilledString(data.datalenleft) or "" 
    119135        HandleStringQuery(data)