Thread

Source code for RelayBot (long) (Sdk)

Source code for RelayBot (long) // Sdk

1  |  

tacoguy

Feb 22, 2002, 1:43am
Hello all !

I am posting this code in hopes that it can be a source of information
for new people so they do not have to go thru the brain damage I did
to make a bot. It is not authorative and only partial code is here as
there are actually 3 bots but this is a start.

This includes ability to store/retrieve location data, use multiple
cit# and encrypt / decrypt passwords.

Please don't throw stones at me for code imperfections ... there
simply was no information available other than what very little I
could get from this NG.

This is Visual Basic

Best as always !

Tacoguy

**************************************

' *******************Formbot1******************


' RelayBot by Tacoguy
' Allows 3 Bots to enter any world in any location
' Parameters such as location and owner can be saved and restored
' The Bots listen to chat and send chat to the other 2 Bots
' This enables large areas of a world to be "chat enabled"
' 2 Cit#'s are allowed to avoid maximum Bots exceeded by the UniServer


Private Const BotName1 = "Relay1"
Private Const Application = "RelayBot"
Private Const Universe = "auth.activeworlds.com"
Private Const Port = 5670
Private Const MyYaw = 0
Public rc1 As Long
Public Bot1NS
Public Bot1WE
Public Bot2NS
Public Bot2WE
Public Bot3NS
Public Bot3WE

Private Sub Check1_Click()


'Checkbox if saving is enabled

Command4.Enabled = True
Check1.Visible = False

End Sub

Private Sub Check2_Click()

If Check2.Value = 1 Then
NS3.Enabled = True
WE3.Enabled = True
ALT3.Enabled = True
AV3.Enabled = True
WLD3.Enabled = True
UseCit3.Enabled = True
Cit2.Enabled = True
Pass2.Enabled = True

End If

If Check2.Value = 0 Then
NS3.Enabled = False
WE3.Enabled = False
ALT3.Enabled = False
AV3.Enabled = False
WLD3.Enabled = False
UseCit3.Enabled = False
Cit2.Enabled = True
Pass2.Enabled = True
End If

End Sub

Private Sub Command1_Click()

Bot2on.Value = 0 'Tells other bots that Bot2 is off

Bot3on.Value = 0 'Tells other bots that Bot3 is off

Text16.Text = "Logging In Relay1"

'Instance 1

sdk.AwInit AW_BUILD ' Init the API

sdk.AwCreate Universe, Port ' Gets ready to log into the universe

'sdk.EnableDefaultEvents ' Allows the bot to receive events
sdk.AwEventSet AW_EVEN_AVATAR_ADD
sdk.AwEventSet AW_EVENT_CHAT

'All of these below set the login parameters

sdk.AwLoginApplication = Application

'Cit Used
If Formbot1.UseCit1 = "2" Then
sdk.AwLoginOwner = Cit2
Else
sdk.AwLoginOwner = Cit
End If

'Pass Used
If Formbot1.UseCit1 = "2" Then
sdk.AwLoginPrivilegePassword = Pass2
Else
sdk.AwLoginPrivilegePassword = Pass
End If

sdk.AwLoginName = BotName1

rc1 = sdk.AwLogin 'Performs the login

If rc1 = 0 Then
Text16.Text = "Relay1 is Logged in OK"
Else
Text16.Text = (rc1 & ": " & sdk.RCLookUp(rc))
End If

sdk.AwEnter WLD1 'World 'This enters the world.

ns1a = Bot1NS * 1000
we1a = Bot1WE * 1000
ALT1A = ALT1 * 100

' The lines below specify the location of the bot within the world.
IF you ommit the lines here, the bot will still be in the world, only
invisible and will be limited to only a few functions.

sdk.AwMyType = AV1 'MyType
sdk.AwMyX = we1a 'MyX
sdk.AwMyY = ALT1A 'MyY
sdk.AwMyZ = ns1a 'MyZ
sdk.AwMyYaw = MyYaw

' Starts the aw wait timer

thisSession1 = sdk.AwSession()

timAwWait1.Interval = 1000
timAwWait1.Enabled = True


sdk.AwStateChange

Command2.Enabled = True
Command5.Enabled = True
Command1.Enabled = False
Command2.Visible = True
Command5.Visible = True
Command1.Visible = False

End Sub

Private Sub Command10_Click()

'This starts the bots

'makes sure there are no empty boxes

If NS1.Text = "" Then
MsgBox "Please enter N/S value for Bot1"
GoTo NoData
ElseIf NS2.Text = "" Then
MsgBox "Please enter N/S value for Bot2"
GoTo NoData
ElseIf WE1.Text = "" Then
MsgBox "Please enter W/E value for Bot1"
GoTo NoData
ElseIf WE2.Text = "" Then
MsgBox "Please enter W/E value for Bot2"
GoTo NoData
ElseIf ALT1.Text = "" Then
MsgBox "Please enter Altitude value for Bot1"
GoTo NoData
ElseIf ALT2.Text = "" Then
MsgBox "Please enter Altitude value for Bot2"
GoTo NoData
ElseIf AV1.Text = "" Then
MsgBox "Please enter Avatar value for Bot1"
GoTo NoData
ElseIf AV2.Text = "" Then
MsgBox "Please enter Avatar value for Bot2"
GoTo NoData
ElseIf WLD1.Text = "" Then
MsgBox "Please enter World name for Bot1"
GoTo NoData
ElseIf WLD2.Text = "" Then
MsgBox "Please enter World name for Bot2"
GoTo NoData
ElseIf Cit.Text = "" Then
MsgBox "Please enter Cit #1"
GoTo NoData
ElseIf Pass.Text = "" Then
MsgBox "Please enter Priv Pass for Cit #1"
GoTo NoData
ElseIf Cit2.Text = "" Then
MsgBox "Please enter Cit #2"
GoTo NoData
ElseIf Pass2.Text = "" Then
MsgBox "Please enter Priv Pass for Cit #2"
GoTo NoData
End If

'bot 3 is enabled
If Check2.Value = 0 Then
GoTo Ready
End If

If NS3.Text = "" Then
MsgBox "Please enter N/S value for Bot3"
GoTo NoData
ElseIf WE3.Text = "" Then
MsgBox "Please enter W/E value for Bot3"
GoTo NoData
ElseIf ALT3.Text = "" Then
MsgBox "Please enter Altitude value for Bot3"
GoTo NoData
ElseIf AV3.Text = "" Then
MsgBox "Please enter Avatar value for Bot3"
GoTo NoData
ElseIf WLD3.Text = "" Then
MsgBox "Please enter World name for Bot3"
GoTo NoData
End If

Ready:

Command1.Enabled = True
Command1.Value = True
'Command1.Visible = True
Command10.Visible = False
Check2.Enabled = False

NoData:
End Sub

Private Sub Command5_Click()

Text16.Text = "Logging In as Relay2"

'Instance 2

Load Formbot2

Command1.Visible = False

End Sub



Private Sub Command7_Click()

Text16.Text = "Logging In Relay3"

'Instance 3

Load Formbot3


End Sub

Private Sub Command8_Click()

sdk.AwSay Textin.Text


End Sub

Private Sub sdk_EventChat()

TextChat1.Text = vbNewLine & sdk.AwChatMessage

If sdk.AwAvatarName = "[Relay1]" Then
GoTo Ignore
End If
If sdk.AwAvatarName = "[Relay2]" Then
GoTo Ignore
End If
If sdk.AwAvatarName = "[Relay3]" Then
GoTo Ignore
End If


Command8.Value = False

If Bot2on.Value = 1 Then
Formbot2.Textin.Text = "{" & sdk.AwAvatarName & "}" & TextChat1.Text
Formbot2.Command1.Value = True
Else
End If

If Formbot1.Bot3on.Value = 1 Then
Formbot3.Textin.Text = "{" & sdk.AwAvatarName & "}" & TextChat1.Text
Formbot3.Command1.Value = True
Else
End If

Ignore:
End Sub

Private Sub Command2_Click()

'We done and close things and reset for another round

Text16.Text = "All Relays have logged off"

timAwWait1.Enabled = False ' Stops the timers
Formbot2.timAwWait1.Enabled = False
Formbot3.timAwWait1.Enabled = False

sdk.AwTerm ' Kills the SDK

Unload Formbot3
Unload Formbot2

Command10.Visible = True
Command10.Enabled = True
Command2.Enabled = False
Command2.Visible = False
Command3.Visible = True
Command3.Enabled = True
Command5.Visible = False
Command7.Visible = False
Bot2on.Value = 0 'Tells other bots that Bot2 is off
Bot3on.Value = 0 'Tells other bots that Bot3 is off
Check2.Enabled = True

Text16.Text = "All Relays have logged off"

End Sub

Private Sub Form_Unload(Cancel As Integer)

timAwWait1.Enabled = False ' Stops the timers

sdk.AwTerm ' Kills the SDK

Unload Formbot3
Unload Formbot2
Unload Formbot0
Unload Me

End Sub



Private Sub timAwWait1_Timer()

sdk.AwWait 0

End Sub


Private Sub sdk_EventAvatarAdd()

'When another user enters the world....

sdk.AwWhisper sdk.AwAvatarSession, "Hi " & sdk.AwAvatarName & " !
I am RelayBot1"

End Sub

Private Sub Command4_Click()

'Makes the file that saves data

'encrypt passwords

ePass = "rtutz" 'sets the encrypt pass

NewPass = EncryptText((Pass), ePass)

NewPass2 = EncryptText((Pass2), ePass)

Open "parameters.txt" For Output As #1

Print #1, Cit.Text
Print #1, NewPass
Print #1, Cit2.Text
Print #1, NewPass2
Print #1, WLD1.Text
Print #1, UseCit1.Text
Print #1, NS1.Text
Print #1, WE1.Text
Print #1, Int(ALT1.Text)
Print #1, AV1.Text
Print #1, WLD2.Text
Print #1, UseCit2.Text
Print #1, NS2.Text
Print #1, WE2.Text
Print #1, Int(ALT2.Text)
Print #1, AV2.Text
Print #1, WLD3.Text
Print #1, UseCit3.Text
Print #1, NS3.Text
Print #1, WE3.Text
Print #1, Int(ALT3.Text)
Print #1, AV3.Text
Print #1, Check2.Value

Close #1

End Sub
Private Sub Command3_Click()

'Gets the file that has the data

Open "parameters.txt" For Input As #1
Dim data

Do Until EOF(1)
Line Input #1, data
Cit.Text = data
Line Input #1, data
Pass.Text = data
Line Input #1, data
Cit2.Text = data
Line Input #1, data
Pass2.Text = data
Line Input #1, data
WLD1.Text = data
Line Input #1, data
UseCit1.Text = data
Line Input #1, data
NS1.Text = data
Line Input #1, data
WE1.Text = data
Line Input #1, data
ALT1.Text = data
Line Input #1, data
AV1.Text = data
Line Input #1, data
WLD2.Text = data
Line Input #1, data
UseCit2.Text = data
Line Input #1, data
NS2.Text = data
Line Input #1, data
WE2.Text = data
Line Input #1, data
ALT2.Text = data
Line Input #1, data
AV2.Text = data
Line Input #1, data
WLD3.Text = data
Line Input #1, data
UseCit3.Text = data
Line Input #1, data
NS3.Text = data
Line Input #1, data
WE3.Text = data
Line Input #1, data
ALT3.Text = data
Line Input #1, data
AV3.Text = data
Line Input #1, data
Check2.Value = data

Loop

Close #1

'decrypt passwords

ePass = "MYPASSHERE" 'sets the decrypt pass

Pass.Text = DecryptText((Pass), ePass)

Pass2.Text = DecryptText((Pass2), ePass)

' convert N/S and W/E coords to + and - values

Bot1NSA = NS1.Text
Bot2NSA = NS2.Text
Bot3NSA = NS3.Text
Bot1WEA = WE1.Text
Bot2WEA = WE2.Text
Bot3WEA = WE3.Text

Dim NSC As String

NSC = Bot1NSA
GoSub NSCalc
Bot1NS = NSC

NSC = Bot2NSA
GoSub NSCalc
Bot2NS = NSC

NSC = Bot3NSA
GoSub NSCalc
Bot3NS = NSC

GoTo ReadyWE

NSCalc:
'Determine if N or S from string

x = InStr(NSC, "S")

If x > 0 Then
North = "-"
GoTo FoundN
End If

x = InStr(NSC, "s")

If x > 0 Then
North = "-"
GoTo FoundN
Else: North = ""
End If

'Strip the N/S away from the string

FoundN:

CleanN = Clean1(NSC)

'Make a new + / - string

NSC = North & CleanN

Return

ReadyWE:

Dim WEC As String

WEC = Bot1WEA
GoSub WECalc
Bot1WE = WEC

WEC = Bot2WEA
GoSub WECalc
Bot2WE = WEC

WEC = Bot3WEA
GoSub WECalc
Bot3WE = WEC

GoTo CalcDone

WECalc:
'Determine if W or E from string

x = InStr(WEC, "E")

If x > 0 Then
West = "-"
GoTo FoundW
End If

x = InStr(WEC, "e")

If x > 0 Then
West = "-"
GoTo FoundW
Else: West = ""
End If

'Strip the W/E away from the string

FoundW:
cleanW = Clean(WEC)

'Make a new + / - string

WEC = West & cleanW

Return

CalcDone:

Command3.Visible = False

End Sub

'Encrypt passwords
Private Function EncryptText(strText As String, ByVal strPwd As
String)
Dim i As Integer, c As Integer
Dim strBuff As String

#If Not CASE_SENSITIVE_PASSWORD Then

'Convert password to upper case
'if not case-sensitive
strPwd = UCase$(strPwd)

#End If

'Encrypt string
If Len(strPwd) Then
For i = 1 To Len(strText)
c = Asc(Mid$(strText, i, 1))
c = c + Asc(Mid$(strPwd, (i Mod Len(strPwd)) + 1, 1))
strBuff = strBuff & Chr$(c And &HFF)
Next i
Else
strBuff = strText
End If
EncryptText = strBuff
End Function

'Decrypt passwords
Private Function DecryptText(strText As String, ByVal strPwd As
String)
Dim i As Integer, c As Integer
Dim strBuff As String


'Convert password to upper case
'if not case-sensitive
strPwd = UCase$(strPwd)


'Decrypt string
If Len(strPwd) Then
For i = 1 To Len(strText)
c = Asc(Mid$(strText, i, 1))
c = c - Asc(Mid$(strPwd, (i Mod Len(strPwd)) + 1, 1))
strBuff = strBuff & Chr$(c And &HFF)
Next i
Else
strBuff = strText
End If
DecryptText = strBuff
End Function

Public Function Clean(WEC As String) As String
Dim nLength As Integer
Dim nStart As Integer
Dim sOne As String
Dim sNoWay As String
'
sNoWay = " ',-.()!_$*<>/\?;:=+NnSsWwEe"

If Not IsNull(WEC) Then
nLength = Len(WEC)
nStart = 1
Do While nStart <= nLength
sOne = Mid(WEC, nStart, 1)
If InStr(1, sNoWay, sOne, vbTextCompare) = 0 Then
Clean = Clean & sOne
End If
nStart = nStart + 1
Loop
End If
End Function

Public Function Clean1(NSC As String) As String
Dim nLength1 As Integer
Dim nStart1 As Integer
Dim sOne1 As String
Dim sNoWay1 As String
'
sNoWay1 = " ',-.()!_$*<>/\?;:=+NnSsWwEe"

If Not IsNull(NSC) Then
nLength1 = Len(NSC)
nStart1 = 1
Do While nStart1 <= nLength1
sOne1 = Mid(NSC, nStart1, 1)
If InStr(1, sNoWay1, sOne1, vbTextCompare) = 0 Then
Clean1 = Clean1 & sOne1
End If
nStart1 = nStart1 + 1
Loop
End If
End Function

1  |  
Awportals.com is a privately held community resource website dedicated to Active Worlds.
Copyright (c) Mark Randall 2006 - 2024. All Rights Reserved.
Awportals.com   ·   ProLibraries Live   ·   Twitter   ·   LinkedIn