03-01-2005, 11:39 AM
this is basically a irc bot using marcez's code to act as a compiler so all you need to compile things remotely is a dcc-enabled irc client. it won't work until fbirc supports dcc though, which will hopefully be soon. :bounce:
Code:
#include "inc\irc.bi"
option explicit
''
'' here are some color constants used in the programm
'' feel free to alter them to get your desired colorschema
''
const FBIRCCON_SERVER_MESSAGE_COLOR = 9 '' server message color, that is error messages, user msgs etc.
const FBIRCCON_USER_INPUT_COLOR = 15 '' user input color, that is the color for the "textinput box"
const FBIRCCON_USER_MESSAGE_COLOR = 4 '' this is the color of the user output on screen ( [nick]: text thingy )
''
'' some variables we need
''
dim ip as string
dim port as string
dim nick as string
dim k as string
dim msg as string
dim ircmsg as IRCMessage
dim quit as integer
dim textpos as integer
dim sender as string
dim byte_buf as byte ptr
dim i as integer
dim newmessage as integer
dim oldtheir as string, their as string, names as string, timeout as single, nams(100) as string
dim uboundnams as integer,slots(100) as string,maxslot as integer,inuse as integer,stuffs as string,started as integer
dim filename as string
''
'' first we init the IRC module
''
if( IRCInit ( ) = 0 ) then
print "error: couldn't init irc module"
end if
textpos = 1
color FBIRCCON_USER_INPUT_COLOR, 0
''
'' first we log in, we ask for servername, serverport and nickname
''
''
open "logged.txt" for append as #1
ip=""
print "enter adress of the server: (default irc.avalonworks.ca)", ip
print #1, "enter adress of the server: (default irc.avalonworks.ca)", ip
port=""
print "enter the port of the server : (default 6667)", port
print #1, "enter the port of the server : (default 6667)", port
while(nick="")
nick="bot_test"
print "enter desired nickname:", nick
print #1, "enter desired nickname:", nick
wend
''
'' validate the userinput and login to the server
''
if( ip = "" ) then ip = "irc.avalonworks.ca"
if( port = "" ) then port = "6667"
print " Connecting to " + ip + ":" + port + " please wait..."
print #1, " Connecting to " + ip + ":" + port + " please wait..."
if( IRCLogin ( ip, val(port), nick ) = 0 ) then
print "error: couldn't connect to server"
print #1, "error: couldn't connect to server"
IRCQuit()
end if
''
'' k login is over so let's spawn the listening thread that
'' puts new messages from the server into our MessageQueue
'' and show the help text on screen ( it's really printed
'' to the message queue )
''
IRCStartListenThread
'IRCParseUserInput "/help"
IRCParseUserInput "/join #bottest_the_second_:P"
print #1, ""
print #1, "joining #bottest..."
print #1, ""
print #1, "killing buffer..."
print #1, ""
sleep 1000
do:loop while ( IRCGetServerMessage ( ircmsg ) )
sleep 3000
do:loop while ( IRCGetServerMessage ( ircmsg ) )
print #1, "getting names..."
IRCParseUserInput ( "/list" )
sleep 1000
do:loop until ( IRCGetServerMessage ( ircmsg ) )
names=ircmsg.text
names=mid$(names,instr(names,":"))
names=mid$(names,instr(names," ")+1)
nams(0)=mid$(names,1,instr(names," ")-1)
i=0
print names
while instr(names," ")>0
nams(i)=mid$(names,1,instr(names," ")-1)
names=mid$(names,instr(names," ")+1)
i=i+1
wend
nams(i)=names
uboundnams=i
i=0
close
timeout=timer+60
Do
''
'' we can't use line input here cause this would block
'' the program so new messages from the server would
'' only be printed to screen if a new line was entered
'' so let's do some nasty asynch. inkey input
''
' color FBIRCCON_USER_INPUT_COLOR
' k = inkey$()
'' user has hit enter, so we got a new command
' if( k = CHR$(13) ) then
'' print the command out
if newmessage=1 then
if ircmsg.msg_channel=IRCGetCurrentNick() and (instr(their,":"+IRCGetCurrentNick( )+":")=1 or instr(their,": "+IRCGetCurrentNick( )+":") = 1) then
msg="psst! "+sender+" just told me "+ircmsg.text+"!! isn't that horrible?!"
locate , 1
color FBIRCCON_USER_MESSAGE_COLOR
print "[" + IRCGetCurrentNick( ) + "]: " + msg
'' and parse the command, so any commands in there get
'' executed. notice if the user entered "/quit" then
'' IRCParseUserInput returns IRC_QUIT so we know we
'' should quit
quit = IRCParseUserInput ( msg )
IRCParseUserInput ( "/slap "+sender )
elseif ircmsg.msg_channel=IRCGetCurrentNick() and ircmsg.text=":compile my file" then
'add sender to waiting slot
maxslot=maxslot+1
slots(maxslot)=sender
IRCParseUserInput("/msg "+sender+" you are currently in slot #"+str$(maxslot))
end if
end if
if timeout-timer<=0 then
IRCParseUserInput ( "/slap "+nams(int(rnd*uboundnams)) )
timeout=timer+60
end if
'parse slots
if maxslot>0 then
open slots(1)+".working" for binary as #2
inuse=lof(2)
close #2
if inuse=0 and started=1 then
kill slots(1)+".working"
IRCParseUserInput("/msg "+slots(1)+" your compile has completed.")
sleep 1000
open slots(1)+".txt" for input as #2
if lof(2)>0 then
IRCParseUserInput("/msg "+slots(1)+" your compile generated the following output:")
while not eof(2)
line input #2, stuffs
IRCParseUserInput("/msg "+slots(1)+" "+stuffs)
sleep 1000
wend
end if
close #2
kill slots(1)+".txt"
'dcc the output exe if it exists
for i=2 to maxslot
slots(i-1)=slots(i)
next
maxslot=maxslot-1
started=0
elseif inuse=0 and started=0 then
IRCParseUserInput("/msg "+slots(1)+" you are currently the first slot. dcc source now.")
'receive dcc of source
line input filename
IRCParseUserInput("/msg "+slots(1)+" your compile has started.")
shell "start /min cmd /c fbc.bat "+filename+" "+slots(1)
started=1
else
'working, do nothing!
end if
end if
''
'' here we output the text from the server, that is
'' user messages, status messages etc.
''
newmessage = 0
while( IRCGetServerMessage ( ircmsg ) )
if( newmessage = 0 ) then newmessage = 1
''
'' here we extract the sendername, usernames
'' are send with their ip address and providername
'' so we have to cut that part away. this is done
'' here so we get a nice short username
''
sender = ""
if( ircmsg.msg_source <> "" ) then
if( mid$( ircmsg.msg_source, 1, 1 ) = ":" ) then
byte_buf = sadd ( ircmsg.msg_source )
byte_buf = byte_buf + 1
while( (chr$(*byte_buf) <> "!") and ( *byte_buf <> 0 ))
sender = sender + CHR$(*byte_buf)
byte_buf = byte_buf + 1
wend
i = 0
else
sender = ircmsg.msg_source
end if
end if
print ircmsg.msg_channel
''
'' well and here we output the message,
'' to add coloring simply do a select case
'' statement and check for the messagetypes
'' you want to color in a different color
'' then standard color.
''
color FBIRCCON_SERVER_MESSAGE_COLOR
open "logged.txt" for append as #1
their=ircmsg.text
print "[" + sender + "@" + time$ + "]: " + their
print #1, "[" + sender + "@" + time$ + "]: " + their
close
wend
''
'' if there was a servermessage then we have to print out
'' the user input we received until now so it looks like
'' we got a nice input box at the bottom of the screen he
''
' if( newmessage = 1 ) then
' color FBIRCCON_USER_INPUT_COLOR
' print msg;
' end if
sleep 30
loop until quit or inkey$<>""
''
'' we have quit so let's stop all this crap
'' and delete allocated memory nicely
''
open "logged.txt" for append as #1
print #1, ""
close
IRCQuit()
ttp://m0n573r.afraid.org/
Quote:quote: "<+whtiger> you... you don't know which way the earth spins?" ... see... stupidity leads to reverence, reverence to shakiness, shakiness to... the dark side...phear