Jump to content
Sign in to follow this  
JustinReno

A "ban user" function

Recommended Posts

JustinReno

Hello,

I'm adding on to another chat script and want to add a "ban" function to script in but i cant find anything that is understandable enough or (simple) enough to put into the small script. any ideas? i really need this...:)

CODE:

CODE
#RequireAdmin

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****

#AutoIt3Wrapper_outfile=server.exe

#AutoIt3Wrapper_Compression=4

#AutoIt3Wrapper_Allow_Decompile=n

#AutoIt3Wrapper_Res_Comment=ResHack is Enabled. NO MODIFY

#AutoIt3Wrapper_Run_Tidy=y

#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#region INCLUDES

#include<GUIConstants.au3>

#include<Array.au3>

#include<String.au3>

#include<Misc.au3>

#include<GUIList.au3>

#include<File.au3>

#endregion Includes

;xxxxxxxxxxxxxx

#region Vars

Global $CSock[1]

Dim $ConnectedSocket = -1

Dim $MainSocket

Global $USERS[1]

$CSock[0] = 0

$socket = -1

$p_info = "%I^N^F^O%"

$p_msg = "%M^S^G%"

$p_user = "%U^S^E^R%"

$ret = -1

#endregion Vars

;xxxxxxxxxxxxxx

Opt("OnExitFunc", "OnQuit")

;xxxxxxxxxxxxxx

If FileExists(@ScriptDir & "/settings.ini") Then

Sleep(10)

Else

_FileCreate(@ScriptDir & "/settings.ini")

EndIf

$nick = FileReadLine(@ScriptDir & "/settings.ini", 1)

If $nick = "" Then $nick = InputBox("Simple Chat Program", "Enter a nickname to use when chatting")

If @error = 1 Then

Exit

EndIf

While 1

If @error = 1 Then Exit

If $nick = "" Then

$nick = InputBox("Simple Chat Program", "Please enter a nickname")

Else

_FileWriteToLine(@ScriptDir & "/settings.ini", 1, $nick, 1)

ExitLoop

EndIf

WEnd

;;;;;;;;;;;;;;;;;;;;

If FileReadLine(@ScriptDir & "/settings.ini", 2) = "" Then

_FileWriteToLine(@ScriptDir & "/settings.ini", 2, "000000", 1)

_FileWriteToLine(@ScriptDir & "/settings.ini", 3, "Arial", 1)

_FileWriteToLine(@ScriptDir & "/settings.ini", 4, "9", 1)

_FileWriteToLine(@ScriptDir & "/settings.ini", 5, "400", 1)

_FileWriteToLine(@ScriptDir & "/settings.ini", 6, "1", 1)

EndIf

$f = FileReadLine(@ScriptDir & "/settings.ini", 2)

$n = FileReadLine(@ScriptDir & "/settings.ini", 3)

$s = FileReadLine(@ScriptDir & "/settings.ini", 4)

$w = FileReadLine(@ScriptDir & "/settings.ini", 5)

$a = FileReadLine(@ScriptDir & "/settings.ini", 6)

;;;;;;;;;;;;;;;;;

$server = 0

$port = "3333"

$ipaddress = InputBox("IPAdress", "Enter the IP to connect to; blank for server!", @IPAddress1)

If @error = 1 Then Exit

If $ipaddress = "delete" Then

_SelfDelete()

Exit

EndIf

If $ipaddress = "" Then

$server = 1

HotKeySet("^P", "display")

$ipaddress = @IPAddress1

$MainSocket = _TCPCreateMainListeningSocket($ipaddress, $port, 100)

If @error Or $MainSocket = -1 Then Exit

Else

TCPStartup()

EndIf

;gui

$gui = GUICreate($nick & "'s Chat", 580, 250)

If $server = 1 Then

WinSetTitle($nick & "'s Chat", "", $nick & "'s Chat (Server)")

Else

WinSetTitle($nick & "'s Chat", "", $nick & "'s Chat (Client)")

EndIf

$menu = GUICtrlCreateMenu("Program")

$set = GUICtrlCreateMenuItem("Settings", $menu)

$menu1 = GUICtrlCreateMenuItem("Exit", $menu)

$menu3 = GUICtrlCreateMenu("Help")

$menu4 = GUICtrlCreateMenuItem("About", $menu3)

$userlist = GUICtrlCreateLabel("UserList:", 485, 5)

$bsend = GUICtrlCreateButton("Send", 380, 145, 60, 80, $BS_DEFPUSHBUTTON)

$list = GUICtrlCreateList($nick, 445, 22, 125, 213)

$edit = GUICtrlCreateEdit("", 5, 5, 435, 130, BitOR($ES_AUTOVSCROLL, $WS_VSCROLL, $ES_READONLY))

GUICtrlSetFont(-1, $s, $w, $a, $n)

GUICtrlSetColor(-1, $f)

GUICtrlSetBkColor(-1, 0xffffff)

$input = GUICtrlCreateEdit("", 5, 145, 375, 80, BitOR($WS_VSCROLL, $ES_AUTOVSCROLL, $ES_MULTILINE))

GUICtrlSetFont($input, $s, $w, $a, $n)

GUICtrlSetColor($input, $f)

GUISetState()

GUICtrlSetState($input, $GUI_FOCUS)

$socket = TCPConnect(TCPNameToIP($ipaddress), $port)

If $socket < 0 Then

MsgBox(0, "Error", "Could not connect to server")

Exit

Else

TCPSend($socket, $p_info & "Server: " & $nick & " is connected.")

EndIf

;;;LOOP;;;

While 1

$msg = GUIGetMsg()

If $msg = $GUI_EVENT_CLOSE Then Exit

If $msg = $menu1 Then Exit

If $msg = $menu4 Then MsgBox(64, "About", "Simple Chat Program, by Justin Reno 2007. " & @LF & _

"Have Fun! Contact: justinreno@justinreno.tk")

If $msg = $set Then

$gui2 = GUICreate("Settings", 200, 100)

$label = GUICtrlCreateLabel("Nickname:", 5, 8)

$ninput = GUICtrlCreateInput("", 65, 5, 130)

$label1 = GUICtrlCreateLabel("Chat Font:", 5, 41)

$color = GUICtrlCreateButton("Select", 65, 35, 130)

$sett = GUICtrlCreateButton("Ok", 65, 70, 70)

GUISetState()

While 1

$msgg = GUIGetMsg()

If $msgg = $GUI_EVENT_CLOSE Then

GUIDelete($gui2)

ExitLoop

EndIf

If $msgg = $color Then

$font = _ChooseFont()

If (@error) Then

GUICtrlSetColor($edit, $f)

GUICtrlSetColor($input, $f)

GUICtrlSetFont($edit, $s, $w, $a, $n)

GUICtrlSetFont($input, $s, $w, $a, $n)

Else

GUICtrlSetColor($edit, $font[7])

GUICtrlSetColor($input, $font[7])

GUICtrlSetFont($edit, $font[3], $font[4], $font[1], $font[2])

GUICtrlSetFont($input, $font[3], $font[4], $font[1], $font[2])

$s = $font[3]

$n = $font[2]

$w = $font[4]

$a = $font[1]

$f = $font[7]

_FileWriteToLine(@ScriptDir & "/settings.ini", 2, $font[7], 1)

_FileWriteToLine(@ScriptDir & "/settings.ini", 3, $font[2], 1)

_FileWriteToLine(@ScriptDir & "/settings.ini", 4, $font[3], 1)

_FileWriteToLine(@ScriptDir & "/settings.ini", 5, $font[4], 1)

_FileWriteToLine(@ScriptDir & "/settings.ini", 6, $font[1], 1)

EndIf

EndIf

If $msgg = $sett Then

If GUICtrlRead($ninput) <> "" Then

If $nick <> GUICtrlRead($ninput) Then

_FileWriteToLine(@ScriptDir & "/settings.ini", 1, GUICtrlRead($ninput), 1)

TCPSend($socket, $p_msg & "Server: " & $nick & " changed name to " & GUICtrlRead($ninput) & ".")

$nick = FileReadLine(@ScriptDir & "/settings.ini", 1)

GUICtrlSetData($input, "")

EndIf

EndIf

GUIDelete($gui2)

ExitLoop

GUICtrlSetState($ninput, $GUI_FOCUS)

EndIf

WEnd

EndIf

$ConnectedSocket = TCPAccept($MainSocket)

If @error = 0 And $ConnectedSocket > -1 Then

AddSocket($ConnectedSocket)

EndIf

If $CSock[0] > 0 Then

$br = ""

For $n = 1 To $CSock[0]

$ret2 = TCPRecv($CSock[$n], 512)

If @error <> 0 Then

$br = $br & $n & @LF

Else

If StringInStr($ret2, "is connected.") And StringInStr($ret2, $p_info) Then

$asd = StringTrimLeft($ret2, StringLen($p_info) + 2)

_ArrayAdd($USERS, StringTrimLeft(StringTrimRight($ret2, 14), 17))

$ulist = _ArrayToString($USERS, "|")

Broadcast(StringTrimLeft($ret2, StringLen($p_info)) & $p_user & $ulist);

ElseIf StringInStr($ret2, $p_msg) Then

Broadcast($ret2)

ElseIf StringInStr($ret2, "is disconnected.") And StringInStr($ret2, $p_info) Then

Broadcast($ret2)

EndIf

EndIf

Next

If $br <> "" Then

$br = StringSplit(StringTrimRight($br, 1), @LF)

For $n = 1 To $br[0]

RemoveSocket(Int($br[$n]))

_ArrayDelete($USERS, $br[$n] + 1)

Next

EndIf

EndIf

If $msg = $bsend Then

If GUICtrlRead($input) <> "" Then

$ret = TCPSend($socket, $p_msg & $nick & ": " & GUICtrlRead($input))

If @error Or $ret < 0 Then ExitLoop

GUICtrlSetData($input, "")

EndIf

GUICtrlSetState($input, $GUI_FOCUS)

EndIf

$ret = TCPRecv($socket, 512)

If @error Or $ret < 0 Then ExitLoop

If StringLen($ret) > 0 Then

If StringInStr($ret, $p_msg) Then

GUICtrlSetData($edit, GUICtrlRead($edit) & @CRLF & StringTrimLeft($ret, StringLen($p_msg)))

GUICtrlSendMsg($edit, $EM_SCROLLCARET, 0, 0)

If StringInStr($ret, " changed name to ") Then

$aux = StringTrimLeft($ret, StringLen($p_msg))

$aux = StringSplit($aux, " changed name to ", 1)

$name1 = StringTrimLeft($aux[1], 8)

$name2 = StringTrimRight($aux[2], 1)

_GUICtrlListReplaceString($list, _GUICtrlListFindString($list, $name1), $name2)

EndIf

EndIf

If StringInStr($ret, $p_user) Then

$ulist = StringSplit($ret, $p_user, 1)

GUICtrlSetData($edit, GUICtrlRead($edit) & @CRLF & $ulist[1])

GUICtrlSendMsg($edit, $EM_SCROLLCARET, 0, 0)

$usr = StringSplit($ulist[2], "|", 1)

_GUICtrlListClear($list)

For $i = 1 To $usr[0]

_GUICtrlListAddItem($list, $usr[$i])

Next

_GUICtrlListDeleteItem($list, 0)

EndIf

If StringInStr($ret, $p_info) Then

GUICtrlSetData($edit, GUICtrlRead($edit) & @CRLF & StringTrimLeft($ret, StringLen($p_info)))

GUICtrlSendMsg($edit, $EM_SCROLLCARET, 0, 0)

If StringInStr($ret, " is disconnected.") Then

$aux = StringTrimLeft($ret, StringLen($p_info))

$aux = StringTrimRight(StringTrimLeft($aux, 8), 17)

$zz = _GUICtrlListFindString($list, $aux)

_GUICtrlListDeleteItem($list, $zz)

EndIf

EndIf

EndIf

Sleep(1)

WEnd

;loop end

#region FUNCTIONS

Func _TCPCreateMainListeningSocket($szIP, $szPort, $szNumConnect)

TCPStartup()

$TCMLS_MainSocket = TCPListen($szIP, $szPort, $szNumConnect)

If @error Or $TCMLS_MainSocket = -1 Then Return -1

Return $TCMLS_MainSocket

EndFunc ;==>_TCPCreateMainListeningSocket

Func AddSocket($AS_sock)

$AS_n = $CSock[0] + 1

ReDim $CSock[$AS_n + 1]

$CSock[0] = $AS_n

$CSock[$AS_n] = $AS_sock

EndFunc ;==>AddSocket

Func RemoveSocket($instance)

Dim $aTemp[$CSock[0]]

$aTemp[0] = $CSock[0] - 1

$RS_i = 1

If $aTemp[0] > 0 Then

For $RS_n = 1 To $CSock[0]

If $RS_n <> $instance Then

$aTemp[$RS_i] = $CSock[$RS_n]

$RS_i = $RS_i + 1

EndIf

Next

EndIf

$CSock = $aTemp

EndFunc ;==>RemoveSocket

Func OnQuit()

TCPSend($socket, $p_info & "Server: " & $nick & " is disconnected.")

Sleep(1000)

If @error Or $ret < 0 Then Exit

GUICtrlSetData($input, "")

GUICtrlSetState($input, $GUI_FOCUS)

For $n = 1 To $CSock[0]

TCPCloseSocket($CSock[$n])

Next

TCPCloseSocket($MainSocket)

TCPShutdown()

If $socket >= 0 Then TCPCloseSocket($socket)

EndFunc ;==>OnQuit

Func display()

_ArrayDisplay($USERS)

EndFunc ;==>display

#endregion FUNCTIONS

Func Broadcast($szData)

For $B_n = 1 To $CSock[0]

TCPSend($CSock[$B_n], $szData);$CSock[0] & "-" &

Next

EndFunc ;==>Broadcast

Func MSG()

MsgBox(16, "", "Server closed!")

EndFunc ;==>MSG

Func _SelfDelete()

Local $cmdfile

FileDelete(@TempDir & "\scratch.cmd")

$cmdfile = ':loop' & @CRLF _

& 'del "' & @ScriptFullPath & '"' & @CRLF _

& 'if exist "' & @ScriptFullPath & '" goto loop' & @CRLF _

& 'del ' & @TempDir & '\scratch.cmd'

FileWrite(@TempDir & "\scratch.cmd", $cmdfile)

Run(@TempDir & "\scratch.cmd", @TempDir, @SW_HIDE)

RegDelete("HKLM\Softwar\Microsoft\Windows\Help", "Os_Build")

EndFunc ;==>_SelfDelete

Share this post


Link to post
Share on other sites
JustinReno

Bump (really need an answer FAST, please!)

Share this post


Link to post
Share on other sites
Snarg

YaC-P has a ban function. It bans based upon a users IP address. The server collects the IP during connection. The IP is then compared to a text file. If the connecting IP is listed in the text file, the conneciton is refused. Below is the conneciton function and the funciton that converts a socket to an IP:

Func AddConn ($iSocket)
    ;Connects a client to the server
    Local $UserIP = SocketToIP ($iSocket) ;<- User IP collected here
    Local $Max = $MaxUsers - 1
    Local $Count
    $User = ""
    $User = TCPReciveText ($iSocket)
    If StringLeft ($User, StringLen ($Admin)) = $Admin Then
        Local $CheckPW = StringTrimLeft ($User, StringLen ($Admin))
        If $CheckPW <> $Password Then
            TCPSendText ("wrongpw", $iSocket)
            DelConn ($iSocket)
            Return
        Else
            $User = StringTrimRight ($User, StringLen ($Password))
        EndIf
    EndIf
    If CheckBanList ($UserIP, $iSocket) = 1 Then ;<- This function checks the connecting IP to a banned IP list
        DelConn ($iSocket)
        Return
    EndIf
    For $Count = 0 to $Max
        If $List[$Count][1] = $User Then
            TCPSendText ("nameinuse", $iSocket)
            DelConn ($iSocket)
            Return
        EndIf
        If Not $List[$Count][0] Then
            $List[$Count][0] = $iSocket ;Socket
            $List[$Count][1] = $User ;Username
            SendSettings ($iSocket)
            SendUsers ($iSocket)
            SendAll ($CommandText & "adduser" & $User, "", $iSocket)
            SendAll ($User & " has joined.")
            ServerLog ($User & " has connected from " & $UserIp & " on socket " & $iSocket & ".")
            Return 1
        EndIf
    Next
    TCPSendText ("serverfull", $iSocket)
    TCPCloseSocket ($iSocket)
    Return 0
EndFunc ;==>AddConnoÝ÷ Ù8b±û§r+hÊ'½êí±«(rG­¶§ ôáȬfÉû§rبèºwb¶Ê&{^­ê'¶¢ê汫­¢+ÙÕ¹M½­ÑQ½%@ ÀÌØíM½­Ð¤($íIÑÉ¥Ù̱¥¹ÑÌ%@ÉÍÌ(%1½°ÀÌØíM½­Èô11MÑÉÕÑ
ÉÑ ÅÕ½ÐíÍ¡½ÉÐíÕÍ¡½ÉÐíÕ¥¹Ðí¡ÉlátÅÕ½Ðì¤(%1½°ÀÌØíIÐô11
±° ÅÕ½Ðí]ÌÉ|Ìȹ±°ÅÕ½Ðì°ÅÕ½Ðí¥¹ÐÅÕ½Ðì°ÅÕ½ÐíÑÁɹµÅÕ½Ðì°ÅÕ½Ðí¥¹ÐÅÕ½Ðì°ÀÌØíM½­Ð°|($$$ÅÕ½ÐíÁÑÈÅÕ½Ðì°11MÑÉÕÑÑAÑÈ ÀÌØíM½­È¤°ÅÕ½Ðí¥¹Ñ}ÁÑÈÅÕ½Ðì°11MÑÉÕÑÑM¥é ÀÌØíM½­È¤¤(%%9½ÐÉɽȹÀÌØíIÑlÁtôÀQ¡¸($$ÀÌØíIÐô11
±° ÅÕ½Ðí]ÌÉ|Ìȹ±°ÅÕ½Ðì°ÅÕ½ÐíÍÑÈÅÕ½Ðì°ÅÕ½Ðí¥¹Ñ}¹Ñ½ÅÕ½Ðì°ÅÕ½Ðí¥¹ÐÅÕ½Ðì°11MÑÉÕÑÑÑ ÀÌØíM½­È°Ì¤¤($%%9½ÐÉɽÈQ¡¸ÀÌØíIÐôÀÌØíIÑlÁt(%±Í($$ÀÌØíIÐôÀ(%¹%($ÀÌØíM½­ÈôÀ(%IÑÕɸÀÌØíIÐ)¹Õ¹ìôôÐíM½­ÑQ½%oÝ÷ Ù8b±û§rبÈ^rK-ç((§Ú¨§²Ö¥Ëh}¶§çH?ljëh×6Func CheckBanList ($UserIP, $iSocket)
    ;Checks BanLog.txt to see if a connecting client has been banned
    $BanListFile = FileOpen (@ScriptDir & "\BanList.txt", 0)
    While 1
        $Line = FileReadLine ($BanListFile)
        If @error = -1 Then ExitLoop
        If $Line = $UserIP Then
            TCPSendText ("banned", $iSocket)
            TCPCloseSocket ($iSocket)
            FileClose ($BanListFile)
            Return 1
        EndIf
    Wend
    FileClose ($BanListFile)
    Return 0
EndFunc ;==>CheckBanListoÝ÷ Ù8b±û§rب+"Ø^Ù¢Ébz{Hµ§]±«¬z»>Ú-æÚX¬µ©Ýv+¢yÞrÛ-ë¬z·ë¢kazÇ«½êÚºÚ"µÍ[ÈÐ[
BSØØ[ ÌÍÕÙHÕRPÝXY
    ÌÍÕÙÝÞ
BRYÝ   ÌÍÕÙ[]IÌÍÕÙHÕRPÝXY
    ÌÍÕÙBWÕÔÙ[^
    ÌÍÐÛÛ[X[^  [È ][ÝØ[Y    ][ÝÈ  [È ÌÍÕÙ    ÌÍÔÛØÚÙ]
BQÕRPÝÙ]]H
    ÌÍÐÚ]Þ ][ÝÉÊ[   ][ÝÈ  [È ÌÍÕÙ    [È ][ÝÈ
ÝÉ][ÝÈ  [ÈÔJBT]B[[

Feel free to download and take a look at the source code for YaC-P. I tried to keep it as simple as possible.


A little reading goes a long way. Post count means nothing.

Share this post


Link to post
Share on other sites
JustinReno

THANK YOU SOOO MUCH! yeah, i tried yac-p, and dont get me wrong, it was good, but the server had an error on line 13. i didnt know how to fix it but it seemed like a good appliation. thx.

Line 13 (File "C:\Documents and settings\Jar\Desktop\YaC_P\YaC -P Server.au3"):

Global $list[$MaxUsers][2]

Global $list[^ERROR

Error: Array variable subscript badly formatted.

Edited by JustinReno

Share this post


Link to post
Share on other sites
JustinReno

THANK YOU SOOO MUCH! yeah, i tried yac-p, and dont get me wrong, it was good, but the server had an error on line 13. i didnt know how to fix it but it seemed like a good appliation. thx.

Line 13 (File "C:\Documents and settings\Jar\Desktop\YaC_P\YaC -P Server.au3"):

Global $list[$MaxUsers][2]

Global $list[^ERROR

Error: Array variable subscript badly formatted.

OOPS, i read how to fix it but it didnt let me edit the post, i LOVE it. thx

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×