Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Telnet lua connection

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Extensions
View previous topic :: View next topic  
Author Message
Dark Byte
Site Admin
Reputation: 475

Joined: 09 May 2003
Posts: 25989
Location: The netherlands

PostPosted: Sun Aug 09, 2026 4:11 pm    Post subject: Telnet lua connection Reply with quote

this code will open port 22122 where you can login with any tcp/ip and issue lua commands.
It supports multiline code. To execute the entered code, send a 0-terminator, or ctrl+x

all print commands will also be sent to the connection.

by default the code runs in a seperate thread, but you can use synchronize() in your own code, or add it to this script if you prefer


Code:

local port=22122
local serverterminated=false
local oldprint


createThread(function(t) 
  local ss=createSocketServer(port)
 
  while not (serverterminated or t.Terminated) do
    local clientlist={}
    local c=ss.acceptConnection(true)
   
    if c then

      table.insert(clientlist,c)
   
      if oldprint==nil then --ALL prints go to everyone
        oldprint=print
       
        --local
        printqueue={}
        local printqueuecs=createCriticalSection()
        local printevent=createEvent(false,false)
       
        createThread(function(pt)
         
          while not (pt.terminated or serverterminated) do
            if printevent==nil then
              oldprint("No printevent. printerthread terminating")
              print=oldprint
              return
            end
           
            local wr=printevent.waitFor(1000)
            --oldprint("after printevent.waitFor. wr="..wr)
            if wr==wrSignaled then
              --empty the printqueue
              --oldprint("printing queue")
              local r             
              repeat
                printqueuecs.enter()
                r=table.remove(printqueue,#printqueue)
                printqueuecs.leave()
                --oldprint("r="..tostringx(r))
                if r then             
                  for _,connection in pairs(clientlist) do
                    pcall(function()
                      connection.lock()
                      connection.writeString(r..string.char(13)..string.char(10))
                      connection.unlock()
                    end)
                  end
                end
              until r==nil
             -- oldprint("done printing")
            elseif wr==wrAbandoned then
              oldprint("printwait was abandoned")
              print=oldprint
              return           
            end
          end
          oldprint("printerthread exiting")
          print=oldprint
        end)
       
       
        print=function(...)
          local r,r2=oldprint(...)
          printqueuecs.enter()
          table.insert(printqueue,r)
          printqueuecs.leave()   
          printevent.setEvent()
         
          return r,r2
        end
        hookedprint=true
      end
      oldprint("new connection made")
     
      c.writeString([[CELua server. Press ctrl+x to execute the code
]]);
     
      createThread(function(ct)
        local commandqueue=''     
        while not (serverterminated or ct.Terminated) do
          local b=c.readBytesMin(1)
          if b==nil then
            break;
          end
         
          local si=1         
          for i=1,#b do
            if (b[i]==0) or (b[i]==0x18) then --0 terminator or ctrl+x indicate to execute from here
              b[i]=0
              local s=commandqueue..byteTableToString(b,si):trim()
              _G.teststring=s
             
              if oldprint then
                local f,ferr=loadstring(s)
                if f then 
                  local success,result=pcall(f)               
                 
                  if success then
                    if result then
                      if tostringx then
                        local s=tostringx(result)
                        if s then
                          c.lock()
                          c.writeString(s)
                          c.unlock()
                        end
                      else
                        print(result)
                      end
                    end
                  else
                    c.lock()

                    if result then
                      c.writeString("error:"..result)
                    else
                      c.writeString("error")
                    end

                    c.unlock()
                  end
                else
                  c.lock()
                  c.writeString('Error loading lua script:'..ferr);
                  c.unlock()
                end
              end
         
              commandqueue=''
              si=i+1             
            end         
          end         
         
          --store what's left
          commandqueue=commandqueue..byteTableToString(b,si)         
         
          --if it contains a ctrl+x (0x18) process the lua and return the result
        end
        oldprint("connection lost")
        for index,connection in pairs(clientlist) do
          if connection==c then
            clientlist[index]=nil
            break
          end
        end
        c.destroy()
      end)
    end
 
  end
 
  ss.destroy()
end)

_________________
Tools give you results. Knowledge gives you control.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Extensions All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites