Originally posted by Baltan
Name: Better Ban System By: Dark Dragon (Baltan) Version: 1 Dificulty: 3/5 (Medium)
Ok, im finally happy enough without this tutorial to releace it. Thanks to Noel for starting me on this. In this tutorial i wil show you how to add
- UnBan System - Ini system (May upgrade to binary later) - Ini Loading to array - HD Banning - /banlist fix
also, this was coded on MS3.03, but they are similar and the syntax is the same (I already had the fileexist function coded before MSE =P ) but if I accidentaly did not make the right module or something, tell me, and i will check it, but you should figure it out.
ok, so lets start:
Server Side: ----------- ModTypes.bas -----------
In PlayerRec in the unsaved loacal variables add:
HDSerial As String
under you're GuildRec add:
Type BanRec BannedIP As String BannedChar As String BannedBy As String BannedHD As String End Type
This will be used in our public array to store all the data. [ you may want to make them fixed length if you want, but thats up to you ]
now, under the code
Public Guild(1 To MAX_GUILDS) As GuildRec add:
Public Ban() As BanRec
this is our array, it dose not have a 0 to anything,we will ReDim that in later.
now at the bottom, add:
Function GetPlayerHD(ByVal index As Long) As String GetPlayerHD = Player(index).HDSerial End Function
this little function will be used later to Get the Players HD
Thats it for modTypes.bas
---------- modDatabase.bas ----------
At the top add a public Integer called MAX_BANS:
Public MAX_BANS As Integer
this will be used to publicaly store the number of bans we have.
ok
now at the bottom add:
Sub LoadBans() Dim FileName As String Dim I As Integer Dim BNum As Integer FileName = App.Path & "\banlist.ini" MAX_BANS = GetVar(FileName, "Total", "Total") ReDim Ban(0 To MAX_BANS) As BanRec For I = 0 To MAX_BANS If GetVar(FileName, "Ban" & I, "BannedIP") = "" Then Ban(I).BannedIP = GetVar(FileName, "Ban" & I, "BannedIP") Ban(I).BannedChar = GetVar(FileName, "Ban" & I, "BannedChar") Ban(I).BannedBy = GetVar(FileName, "Ban" & I, "BannedBy") Ban(I).BannedHD = GetVar(FileName, "Ban" & I, "BannedHD") End If
Next I End Sub
this sub ReDims the Bans Array and loads all the ban info from the file
now that we can Read bans, we need a way to write them, so under the newly created sub add:
Sub SaveBan(ByVal BanNum As Integer) Dim FileName As String FileName = App.Path & "\banlist.ini" Call PutVar(FileName, "Ban" & BanNum, "BannedIP", Ban(BanNum).BannedIP) Call PutVar(FileName, "Ban" & BanNum, "BannedChar", Ban(BanNum).BannedChar) Call PutVar(FileName, "Ban" & BanNum, "BannedBy", Ban(BanNum).BannedBy) Call PutVar(FileName, "Ban" & BanNum, "BannedHD", Ban(BanNum).BannedHD) End Sub
all this does is saves the ban.
now find you're "BanIndex" sub and change it to:
Sub BanIndex(ByVal BanPlayerIndex As Long, ByVal BannedByIndex As Long) Dim FileName As String, IP As String, bnam As String Dim f As Long, I As Long Dim BNum As Integer, b As Integer Dim MAX_BANS As Long
FileName = App.Path & "\banlist.ini" IP = GetPlayerIP(BanPlayerIndex)
b = 1
For I = 0 To MAX_BANS + 1 If Ban(I).BannedIP = "" Then BNum = I Exit For End If If I = MAX_BANS + 1 Then BNum = MAX_BANS + 1 Exit For End If Next I ' Add there data to a ban slot Ban(BNum).BannedIP = IP Ban(BNum).BannedChar = GetPlayerName(BanPlayerIndex) Ban(BNum).BannedBy = GetPlayerName(BannedByIndex) Ban(BNum).BannedHD = GetPlayerHD(BanPlayerIndex) Call SaveBan(BNum) Call PutVar(FileName, "Total", "Total", GetVar(FileName, "Total", "Total") + 1) MAX_BANS = MAX_BANS + 1 'Alert People Call GlobalMsg(GetPlayerName(BanPlayerIndex) & " has been banned from " & GAME_NAME & " by " & GetPlayerName(BannedByIndex) & "!", White) Call AddLog(GetPlayerName(BannedByIndex) & " has banned " & GetPlayerName(BanPlayerIndex) & ".", ADMIN_LOG) Call AlertMsg(BanPlayerIndex, "You have been banned by " & GetPlayerName(BannedByIndex) & "!") End Sub
this sub will find an open banslot, set the ban, Save it, Incriment the MAX_BANS, save them, and do all the message work :wink:
now we CAN ban people, we need to UN-ban them, so under you're edited BanIndex sub, make a New sub:
Sub UnBanIndex(ByVal BannedPlayerName As String, ByVal DeBannedByIndex As Long) Dim FileName As String, IP As String, bnam As String Dim f As Long, I As Long Dim b As Integer Dim MAX_BANS As Integer
FileName = App.Path & "\banlist.ini"
For I = 0 To MAX_BANS + 1 If LCase$(GetVar(FileName, "Ban" & I, "BannedChar")) = LCase$(BannedPlayerName) Then ' Delete there data to a ban slot Ban(I).BannedIP = "" Ban(I).BannedChar = "" Ban(I).BannedBy = "" Ban(I).BannedHD = "" Call SaveBan(I) 'Alert People Call GlobalMsg(BannedPlayerName & " has been unbanned from " & GAME_NAME & " by " & GetPlayerName(DeBannedByIndex) & "!", White) Call AddLog(GetPlayerName(DeBannedByIndex) & " has unbanned " & BannedPlayerName & ".", ADMIN_LOG) Exit For End If If I = MAX_BANS + 1 Then Call PlayerMsg(DeBannedByIndex, "Player is not banned!", White) End If Next I
End Sub
This will try to find a banned person by the name that is passed into the sub, if it can it will erase their data, and do message work, but if it cant it will allert the banner =]
Done with modDatabase.bas ! :-D
---------- modTCP.bas ----------
ok, now we will check IF a person is banned, so:
find your "IsBanned" function. change it to:
Function IsBanned(ByVal IP As String) As Boolean
Dim FileName As String, fIP As String, fName As String Dim f As Long 'Dim b As Integer Dim bIp As String Dim I As Integer
IsBanned = False FileName = App.Path & "\banlist.ini" For I = 0 To MAX_BANS If Ban(I).BannedIP <> "" Then bIp = Ban(I).BannedIP If IP = bIp Then IsBanned = True Exit Function Else IsBanned = False End If End If Next I End Function
this cycles through All bans and if the IP is not "" it will check if the BannedIP is the Loging in IP.
now, I promised HD Banning, and I hope not to dissapoint =P
so under youre edited IsBanned function, add:
Function IsBannedHD(ByVal HD As String) As Boolean
Dim FileName As String Dim bHD As String Dim I As Integer
IsBannedHD = False FileName = App.Path & "\banlist.ini" For I = 0 To MAX_BANS If Ban(I).BannedHD <> "" Then bHD = Ban(I).BannedHD If HD = bHD Then IsBannedHD = True Exit Function Else IsBannedHD = False End If End If Next I End Function
this function does the same thing at the IsBanned function, except it checks for HD instead of IP.
---------- modHandleData.bas ----------
Packet: NewAccount Dim BIp at the top, it is an integer
under
' Get the data Name = Parse(1) Password = Parse(2) Sex = Parse(3)
add:
If IsBannedHD(Player(index).HDSerial) Then Call AlertMsg(index, "You have been banned from " & GAME_NAME & ", you can no longer play!") Exit Sub End If
Packet: Delete Account
under:
' Get the data Name = Parse(1) Password = Parse(2)
add:
If IsBannedHD(Player(index).HDSerial) Then Call AlertMsg(index, "You have been banned from " & GAME_NAME & ", you can no longer play!") Exit Sub End If
Packet: Login
Under:
' Get the data Name = Parse(1) Password = Parse(2)
Add:
If IsBannedHD(Player(index).HDSerial) Then Call AlertMsg(index, "You have been banned from " & GAME_NAME & ", you can no longer play!") Exit Sub End If
Please tell me you get the geist of this :wink:
Packet: Ban List
Cchange it to:
If LCase$(Parse(0)) = "banlist" Then ' Prevent hacking If GetPlayerAccess(index) < ADMIN_MAPPER Then Call HackingAttempt(index, "Admin Cloning") Exit Sub End If n = 1 'Var Password = HD For I = 0 To MAX_BANS bIp = Ban(I).BannedIP If bIp = "" Then 'skip Else Name = Ban(I).BannedBy s = Ban(I).BannedChar Password = Ban(I).BannedHD Call PlayerMsg(index, n & ": " & s & " ( Banned IP " & bIp & "[" & Password & "] by " & Name & " )", White) n = n + 1 End If Next I Exit Sub End If
Packet: BanDestroy
Make it:
If LCase$(Parse(0)) = "bandestroy" Then ' Prevent hacking If GetPlayerAccess(index) < ADMIN_CREATOR Then Call HackingAttempt(index, "Admin Cloning") Exit Sub End If For n = 0 To MAX_BANS Ban(I).BannedIP = "" Ban(I).BannedChar = "" Ban(I).BannedBy = "" Ban(I).BannedHD = "" Call SaveBan(I) Next n Call PlayerMsg(index, "Ban list destroyed.", White) Exit Sub End If
Make a new packet, under Ban Player Packet, named UnBan Player Packet
' ::::::::::::::::::::::::: ' :: UnBan player packet :: ' ::::::::::::::::::::::::: If LCase$(Parse(0)) = "unbanplayer" Then ' Prevent hacking If GetPlayerAccess(index) < ADMIN_MAPPER Then Call HackingAttempt(index, "Admin Cloning") Exit Sub End If ' The player index Name = Trim$(Parse(1)) Call UnBanIndex(Name, index) Exit Sub End If
now add a new Packet at the bottom, named "HDSerial"
' :::::::::::::::::::::: ' :: HD Serial packet :: ' :::::::::::::::::::::: If LCase$(Parse(0)) = "hdserial" Then Player(index).HDSerial = Parse(1) Exit Sub End If
this will be used to recieve and assign the HDD
Done with HandleData!! :-D
DONE SERVER SIDE!!!!!! :-D :-D
Client Side: ---------- ModClientTCP.bas ----------
Change Sub SendNewAccount to
Sub SendNewAccount(ByVal Name As String, ByVal Password As String, ByVal Sex As Byte) Dim Packet As String
Call SendData("HDSerial" & SEP_CHAR & GetHDSerial("C") & SEP_CHAR & END_CHAR)
Packet = "newaccount" & SEP_CHAR & Trim(Name) & SEP_CHAR & Trim(Password) & SEP_CHAR & END_CHAR Call SendData(Packet) End Sub
know you know where to add it, add
Call SendData("HDSerial" & SEP_CHAR & GetHDSerial("C") & SEP_CHAR & END_CHAR)
to SendDelAccount and SendLogin :wink:
these send the HD Serial packet
Under SendBan, add
Sub SendUnBan(ByVal Name As String) Dim Packet As String
Packet = "UNBANPLAYER" & SEP_CHAR & Name & SEP_CHAR & END_CHAR Call SendData(Packet) End Sub
Sends the Unban player packet
End of ModClientTCP
---------- modDatabase.bas ----------
at the Bottom add:
Public Function GetHDSerial(Optional ByVal DriveLetter As String) As Long Dim fso As Object, Drv As Object, DriveSerial As Long 'Create a FileSystemObject object Set fso = CreateObject("Scripting.FileSystemObject") 'Assign the current drive letter if not specified If DriveLetter <> "" Then Set Drv = fso.GetDrive(DriveLetter) Else Set Drv = fso.GetDrive(fso.GetDriveName(App.Path)) End If
With Drv If .IsReady Then DriveSerial = Abs(.SerialNumber) Else '"Drive Not Ready!" DriveSerial = -1 End If End With 'Clean up Set Drv = Nothing Set fso = Nothing GetHDSerial = DriveSerial End Function
this function will return the HD Serial :wink:
Thats it for modDataBase.bas :wink:
---------- modHandleData.bas ----------
Sub HandleKeypresses ->
Command: Banlist
change to
' Check the ban list If LCase(Mid(MyText, 1, 8)) = "/banlist" Then Call SendBanList MyText = "" Exit Sub End If
this is a bugfix
Under /ban command add:
' unBanning a player If LCase(Mid(MyText, 1, 6)) = "/unban" Then If Len(MyText) > 7 Then MyText = Mid(MyText, 8, Len(MyText) - 7) Call SendUnBan(MyText) MyText = "" End If Exit Sub End If
End Of Client
:-o :-o End Of Tutorial!! :-o :-o
any questions or anything i forgot or just a comliment :wink: , please post!!!
|