chat over network (Sample Programs)

by annoyingcalc ⌂, Saturday, April 13, 2013, 21:22 (1474 days ago)

Yes, this does need lots, of work, I used to have it where there was just chat, no kicking or banning, but now I do, I have made modifications to 2 programs so admins arent banned, (its possible to be unbannable though by modification to the regular)


/ban USER bans a user from the chat, ban list reset whenever the program restarts (I could save it to a text file but I dont really want to)
/kick USER removes a user from the chat, only temporarily.
I am planning on optimizing and adding more things later

But still try it out

Here are the non admin programs
cls:clg
banned$=""
print "Ann0chat v0.1"
input "Username: ",name$
if name$="" then
name$="Guest"
print "Hello, "+name$
endif
input "ip: ",addr$
if addr$="" then
addr$="127.0.0.1"
endif
OnError server
NetConnect addr$, 6667
OffError
netwrite(name$+" joined")
print "Connected"
chat:
if netdata<>0 then
recieve$=netread()
onerror skip
if instr(recieve$," joined")>0 then
if instr(banned$,left(recieve$,instr(recieve$," joined")-1)) then
netwrite left(recieve$,instr(recieve$," joined")-1)+" You are Banned!"
endif
endif
offerror
skip:
if recieve$=" "+name$+" You are Banned!" then
print recieve$
goto ddd
end
endif
if recieve$=" "+name$+" You got Kicked!" then
print recieve$
goto ddd
end
endif
print recieve$
recieve$=""
endif
if key=16777237 then
input">",send$
if instr(send$,"/ban ") then
banned$=banned$+", "+right(send$,length(send$)-5)
netwrite(name$+": "+ right(send$,length(send$)-5)+" You are Banned!")
print "Nice try, don't expect to ban an admin"
else
send$=name$+": "+send$
netwrite(send$)
print send$
endif
endif
goto chat
server:
OffError
print "Starting Server"
NetListen 6667
print "Client Connected"
goto chat
return
ddd:
print "You got banned or kicked"
netwrite(name$+" left")
pause 3

Here is the Admin program

cls:clg
banned$=""
print "Ann0chat v0.1"
input "Username: ",name$
if name$="" then
name$="Admin"
print "Hello, "+name$
endif
input "ip: ",addr$
if addr$="" then
addr$="127.0.0.1"
endif
OnError server
NetConnect addr$, 6667
OffError
netwrite(name$+" joined")
print "Connected"
chat:
if netdata<>0 then
recieve$=netread()
onerror skip
if instr(recieve$," joined")>0 then
if instr(banned$,left(recieve$,instr(recieve$," joined")-1)) then
netwrite left(recieve$,instr(recieve$," joined")-1)+" You are Banned!"
endif
endif
offerror
skip:
if instr(recieve$,name$+" You are Banned!")>0 then
usr$=left(recieve$,instr(recieve$,": ")-1)
ans = confirm(usr$+" tried To ban you should I ban or kick him/her?",true)
if ans=1 then
ans = confirm(usr$+"Ban is yes, kick is no",true)
if ans=1 then
banned$=banned$+", "+usr$
netwrite(usr$+" You are Banned!")
print "User Banned"
netlisten 6667
else
netwrite(usr$+" You got Kicked!")
netlisten 6667
endif
endif
endif

print recieve$
recieve$=""
endif
if key=16777237 then
input">",send$
if instr(send$,"/ban ") then
banned$=banned$+", "+right(send$,length(send$)-5)
netwrite(right(send$,length(send$)-5)+" You are Banned!")
print "User Banned"
print netread
netlisten 6667
else
if instr(send$,"/kick ") then
netwrite(right(send$,length(send$)-5)+" You got Kicked!")
print "User Kicked"
netlisten 6667
endif
send$=name$+": "+send$
netwrite(send$)
print send$
endif
endif
goto chat
server:
OffError
print "Starting Server"
NetListen 6667
print "Client Connected"
goto chat
return


Complete thread:

 RSS Feed of thread

powered by my little forum