Attribute VB_Name = "Packets"
Public InFlat(MaxCon) As String
Public users(MaxCon) As String
Public status(MaxCon) As String
Public CurX(MaxCon) As Integer
Public CurY(MaxCon) As Integer
Public NX(MaxCon) As Integer
Public Direction(MaxCon) As Integer
Public StatusOk(MaxCon) As Boolean
Public NY(MaxCon) As Integer
Public LooktoX As Integer
Public LooktoY As Integer
Public LookTo As Boolean


Public Type ClientT

Name As String
Mission As String
Badge As String
Email As String
DOB As String
Sex As String
Credits As Integer
PhoneNumber As String
Agreement As Integer
Figure As String
Country As String
Level As Integer
InRoom As String
PosX As Double
PosY As Double
WishX As Double
WishY As Double
Consolemission As String
DestX As Double
DestY As Double
Look As String
Password As String
DirectMail As String
BadgeOn As Integer
strip As String
messenger As String
Sit As Boolean

End Type

Public Client() As ClientT
Public Function Packstruc(SData As String, index As Integer)
Dim ThePacketsz As String
Dim shit2 As String

ThePacketsz = Split(SData, " ")(0)

Select Case ThePacketsz


Case "VERSIONCHECK"
    If Split(SData, " ")(1) = "client002" Or Split(SData, " ")(1) = "client003" Then
        SendData index, "ENCRYPTION_OFF"
        SendData index, "SECRET_KEY " & Chr(13) & NewKey
    End If
           
Case "REGISTER"
Dim SplitData As Variant
   SplitData = Split(SData, Chr(13))
   Client(index).Name = CStr(Split(SplitData(0), "=")(1))
   Client(index).Password = CStr(Split(SplitData(1), "=")(1))
   Client(index).Email = CStr(Split(SplitData(2), "=")(1))
   Client(index).Figure = Right(SplitData(3), Len(SplitData(3)) - 7)
   Client(index).DirectMail = CStr(Split(SplitData(4), "=")(1))
   Client(index).DOB = CStr(Split(SplitData(5), "=")(1))
   Client(index).PhoneNumber = CStr(Split(SplitData(6), "=")(1))
   Client(index).Mission = CStr(Split(SplitData(7), "=")(1))
   Client(index).Agreement = CStr(Split(SplitData(8), "=")(1))
   Client(index).Sex = CStr(Split(SplitData(9), "=")(1))
   Client(index).Country = CStr(Split(SplitData(10), "=")(1))
   Client(index).Credits = "0"
   Client(index).messenger = "Welcome to Nubz Hotel"
   Client(index).strip = "0"
   MySQLWrite ("INSERT INTO users ( Username, Password, Email, Figure, DirectMail, DateOfBirth, PhoneNumber, Mission, HasReadAgreement, Sex, Country, Credits, Messenger, Strip, LastOnline ) VALUES ('" & Client(index).Name & "', '" & Client(index).Password & "', '" & Client(index).Email & "', '" & Client(index).Figure & "', '" & DirectMail & "', '" & Client(index).DOB & "', '" & Client(index).PhoneNumber & "', '" & Client(index).Mission & "', '" & Client(index).Agreement & "', '" & Client(index).Sex & "', '" & Client(index).Country & "', '" & Client(index).Credits & "', '" & Client(index).messenger & "', '" & Client(index).strip & "', '" & (Now) & "')")
    

Case "APPROVENAME"
    If UserExists(CStr(Split(SData, " ")(1))) = True Then
        SendData index, "BADNAME"
    End If
        
Case "LOGIN"
Dim temp As String
Dim ad As Integer
Dim x As Integer
    If CheckPassword(CStr(Split(SData, " ")(1)), CStr(Split(SData, " ")(2))) = False Then
        SendData index, "BADNAME"
    Else
        Client(index).Name = CStr(Split(SData, " ")(1))
        Client(index).InRoom = "0"
        MySQLWrite ("UPDATE users SET LastOnline = '" & (Now) & "' WHERE Username = '" & Client(index).Name & "'")
        MySQLQuery ("UPDATE users SET SocketNum = '" & (index) & "' WHERE Username = '" & Client(index).Name & "'")
    End If
        If Right(SData, 2) = " 0" Then
            Client(index).InRoom = "Cafe Ole"
            SendData index, "ROOM_READY " & Chr(13) & "lobby_a 25006"
            SendData index, "OBJECTS WORLD 0 taivas_cafe" & Chr(13) & " 90 roommatic -1 10 0 4" & Chr(13) & " 90 roommatic 1 10 0 4" & Chr(13) & " 90 roommatic 0 10 0 4" & Chr(13) & " 90 cafe_pianoa -1 16 0 0" & Chr(13) & " 90 cafe_pianob -1 15 0 0" & Chr(13) & " 90 cafe_pianoc -1 14 0 0" & Chr(13) & " 90 plant_ftree -1 18 0 0" & Chr(13) & " 90 plant_ftree -1 19 0 0" & Chr(13) & " 90 cafe_barchair 0 15 0 0"
            SendData index, "HEIGHTMAP " & Replace(GetPRoomHeightmap("cafe"), " ", Chr(13))
            temp = ""
        For ad = 1 To Form1.SockI
        On Error GoTo ERR0
            If Form1.sckAccept(ad).State = sckConnected And Client(ad).InRoom = "Cafe Ole" Then
                temp = temp & Client(ad).Name & " " & Replace(GetFigure(Client(ad).Name), Chr(13), "") & GetPStartingPos("cafe") & Replace(GetMission(Client(ad).Name), Chr(13), "") & Chr(13)
            Else
ERR0:
            End If
        Next ad
        Broadcast "USERS " & Chr(13) & temp
        For x = 1 To SockI
            If status(x) <> "" Then
                SendData index, "STATUS " & Chr(13) & status(x)
        End If
        Next x
    End If
    

Case "INFORETRIEVE"
Dim UserObject As String

        If CheckPassword(CStr(Split(SData, " ")(1)), CStr(Split(SData, " ")(2))) = True Then
        
Client(index).Mission = GetMission(Client(index).Name)
Client(index).Figure = GetFigure(Client(index).Name)
Client(index).DOB = GetBirthday(Client(index).Name)
Client(index).PhoneNumber = GetPhoneNumber(Client(index).Name)
Client(index).Mission = GetMission(Client(index).Name)
Client(index).Agreement = GetHasReadAgreement(Client(index).Name)
Client(index).Sex = GetSex(Client(index).Name)
Client(index).Country = GetCountry(Client(index).Name)
Client(index).Level = GetHasSpecialRights(Client(index).Name)
Client(index).Badge = Badgetype(Client(index).Name)

UserObject = "name=" & Client(index).Name & Chr(13) & "email=" & Client(index).Email & Chr(13) & "figure=" & Client(index).Figure & Chr(13) & "birthday=" & Client(index).DOB & Chr(13) & "phonenumber=" & Client(index).PhoneNumber & Chr(13) & "customData=" & Client(index).Mission & Chr(13) & "had_read_agreement=" & Client(index).Agreement & Chr(13) & "sex=" & Client(index).Sex & Chr(13) & "country=" & Client(index).Country & Chr(13) & "has_special_rights=" & Client(index).Level & "badge_type=" & Client(index).Badge & Chr(13)
            
            SendData index, "USEROBJECT" & Chr(13) & UserObject
        End If
        
           
Case "GETORDERINFO"
Dim BuyID As String
Dim FurnID As String
Dim Price As Integer
    BuyID = Split(SData, " ")(2)
    FurniID = MySQLQuery("SELECT id FROM Catalogue WHERE call_id = '" & BuyID & "'")
    Price = MySQLQuery("SELECT price FROM Catalogue WHERE call_id = '" & BuyID & "'")
    SendData index, "ORDERINFO " & Chr(13) & FurniID & Chr(13) & Price

'Case "DELETEFLAT"
'Dim TheID As Integer
'Dim PrivRoomCount As Integer
'TheID = Split(SData, "/")(1)

'MySQLQuery ("DELETE * FROM priv_rooms WHERE RoomID= & '" & TheID & "'")
'PrivRoomCount = Val(MySQLQuery("SELECT AmountOfPrivRooms FROM system")) - 1
'MySQLQuery ("UPDATE system SET AmountOfPrivRooms= '" & PrivRoomCount & "'")


Case "PURCHASE"
Dim Purchase As String
Dim Buyme As String
Dim nooCredits As Integer
Dim NewCredits As Integer
Dim Name As String
Dim details As String
Dim weight As String
Dim otype As String
Dim colour As String
Dim walk As String
Dim ovalue As String
Dim sprite As String
Dim FurniIDz As Integer
    Purchase = Split(SData, " ")(1)
    Purchase = Mid(Purchase, 2)
    nooCredits = Client(index).Credits
    Buyme = MySQLQuery("SELECT price FROM Catalogue WHERE id = '" & Purchase & "'")
        If Val(nooCredits) > Val(Buyme) Then
            NewCredits = Val(nooCredits) - Val(Buyme)
            SendData index, "WALLETBALANCE " & Chr(13) & NewCredits
            MySQLQuery ("UPDATE users SET credits= '" & NewCredits & "' WHERE username = '" & Client(index).Name & "'")
        End If
    Name = MySQLQuery("SELECT name from Catalogue WHERE id = '" & Purchase & "'")
    sprite = MySQLQuery("SELECT sprite from Catalogue where id = '" & Purchase & "'")
    details = MySQLQuery("SELECT details from Catalogue WHERE id = '" & Purchase & "'")
    weight = MySQLQuery("SELECT weight from Catalogue WHERE id = '" & Purchase & "'")
    otype = MySQLQuery("SELECT otype from Catalogue WHERE id = '" & Purchase & "'")
    colour = MySQLQuery("SELECT color from Catalogue WHERE id = '" & Purchase & "'")
    walk = MySQLQuery("SELECT walk from Catalogue WHERE id = '" & Purchase & "'")
    ovalue = MySQLQuery("SELECT ovalue from Catalogue WHERE id = '" & Purchase & "'")
    FurniIDz = Val(MySQLQuery("SELECT FurnitureCount FROM system")) + 1
    OwnedFurniture = MySQLQuery("SELECT OwnedFurnitureID FROM users WHERE username = '" & Client(index).Name & "'")
        If OwnedFurniture = "" Then
            OwnedFurniture = ";"
        End If
    OwnedFurniture = OwnedFurniture & Purchase & ";"
    MySQLQuery ("INSERT INTO hand_items ( name, owner, sprite, details, weight, otype, colour, walk, ovalue ) VALUES ('" & Name & "', '" & Client(index).Name & "', '" & sprite & "', '" & details & "', '" & weight & "', '" & otype & "', '" & colour & "', '" & walk & "', '" & ovalue & "')")
    MySQLQuery ("UPDATE system SET FurnitureCount= '" & FurniIDz & "'")
    MySQLQuery ("UPDATE users SET OwnedFurniture= '" & OwnedFurniture & "' WHERE username = '" & Client(index).Name & "'")
    SendData index, "ADDSTRIPITEM"

Case "GETCREDITS"
    Client(index).Credits = MySQLQuery("SELECT Credits FROM users WHERE Username = '" & Client(index).Name & "'")
    SendData index, "WALLETBALANCE " & Chr(13) & Client(index).Credits
    SendData index, "MESSENGERSMSACCOUNT " & Chr(13) & "noaccount"

Case "UPDATE"
SplitData = Split(SData, Chr(13))
    Client(index).Password = CStr(Split(SplitData(1), "=")(1))
    Client(index).Email = CStr(Split(SplitData(2), "=")(1))
    Client(index).Figure = Right(SplitData(3), Len(SplitData(3)) - 7)
    Client(index).PhoneNumber = CStr(Split(SplitData(6), "=")(1))
    Client(index).Mission = CStr(Split(SplitData(7), "=")(1))
    Client(index).Sex = CStr(Split(SplitData(9), "=")(1))
    Client(index).Country = CStr(Split(SplitData(10), "=")(1))
    MySQLQuery ("UPDATE users SET Mission= '" & Client(index).Mission & "' WHERE Username = '" & Client(index).Name & "'")
    MySQLQuery ("UPDATE users SET Email= '" & Client(index).Email & "' WHERE Username = '" & Client(index).Name & "'")
    MySQLQuery ("UPDATE users SET Sex= '" & Client(index).Sex & "' WHERE Username = '" & Client(index).Name & "'")
    MySQLQuery ("UPDATE users SET Figure= '" & Client(index).Figure & "' WHERE Username = '" & Client(index).Name & "'")
    MySQLQuery ("UPDATE users SET Password= '" & Client(index).Password & "' WHERE Username = '" & Client(index).Name & "'")
    MySQLQuery ("UPDATE users SET Country= '" & Client(index).Password & "' WHERE Username = '" & Client(index).Name & "'")
    MySQLQuery ("UPDATE users SET PhoneNumber= '" & Client(index).PhoneNumber & "' WHERE Username = '" & Client(index).Name & "'")

Case "INITUNITLISTENER"
Dim i As Integer
Dim PubRoomName As String
Dim AmountInPRoom As Integer
Dim MaxinPRoom As Integer
Dim Dontknow As String
Dim PHeightmap As String
Dim PRoomPart As String
Dim AmountOfPubRooms As String
Dim PubRooms As String
Dim s As Integer
Dim RoomName As String
Dim RoomOwner As String
Dim MaxinRoom As Integer
Dim AmountInRoom As Integer
Dim RoomDesc As String
Dim RoomType As String
Dim PrivRooms As String
Dim b As Integer
    
Case "FINDUSER"
Dim SearchUser As String
Dim LastOnline As String
Dim ConsoleFigure As String
Dim ConsoleSex As String
Dim ConsoleStatus As String
Dim Consolemission As String
    SearchUser = Split(SData, " ")(1)
        If MySQLExists("SELECT username FROM users WHERE username = '" & SearchUser & "'") = True Then
            LastOnline = MySQLQuery("SELECT lastonline FROM users WHERE username = '" & SearchUser & "'")
            ConsoleFigure = MySQLQuery("SELECt figure FROM users WHERE username = '" & SearchUser & "'")
            ConsoleSex = MySQLQuery("SELECT sex FROM users where username = '" & SearchUser & "'")
            ConsoleStatus = MySQLQuery("SELECT status FROM users WHERE username = '" & SearchUser & "'")
            Consolemission = MySQLQuery("SELECT messenger fROM users where username = '" & SearchUser & "'")
            SendData index, "MEMBERINFO MESSENGER" & Chr(13) & SearchUser & Chr(13) & Consolemission & Chr(13) & LastOnline & Chr(13) & ConsoleStatus & Chr(13) & ConsoleFigure & Chr(13) & ConsoleSex & Chr(13)
        Else
            SendData index, "NOSUCHUSER MESSENGER" & Chr(13) & "Cantfinduser"
        End If

Case "GETFLATINFO"
Dim ModifyID As Integer
Dim Allrights As String
    Allrights = MySQLQuery("SELECT SuperRights from priv_rooms Where RoomID = '" & ModifyID & "'")
    ModifyID = Split(SData, "/")(1)
    RoomDesc = MySQLQuery("SELECT RoomDesc FROM priv_rooms WHERE RoomID = '" & ModifyID & "'")
    RoomPass = MySQLQuery("SELECT RoomPass FROM priv_rooms WHERE RoomID = '" & ModifyID & "'")
    RoomName = MySQLQuery("SELECT RoomName FROM priv_rooms WHERE RoomID = '" & ModifyID & "'")
    RoomType = MySQLQuery("SELECT RoomStatus FROM priv_rooms WHERE RoomID = '" & ModifyID & "'")
    SendData index, "SETFLATINFO" & Chr(13) & "/" & ModifyID & "/description=" & RoomDesc & Chr(13) & "password=" & RoomPass & Chr(13) & "allsuperuser=" & Allrights & Chr(13) & "wordfilter_disable=" & Chr(13)

Case "SETFLATINFO"
    ModifyID = Split(SData, "/")(1)
    RoomDesc = Split(SData, "=")(1)
    RoomDesc = Split(RoomDesc, Chr(13))(0)
    MySQLQuery ("UPDATE priv_rooms SET RoomDesc= '" & RoomDesc & "' WHERE RoomID = '" & ModifyID & "'")
    
Case "UPDATEFLAT"
Dim NRoomID As Integer
Dim NRoomName As String
Dim NRoomStatus As String
    NRoomID = Split(SData, "/")(1)
    NRoomName = Split(SData, "/")(2)
    NRoomStatus = Split(SData, "/")(3)
    MySQLQuery ("UPDATE priv_rooms SET RoomName= '" & NRoomName & "' WHERE RoomID = '" & NRoomID & "'")
    MySQLQuery ("UPDATE priv_rooms SET RoomStatus= '" & NRoomStatus & "' WHERE RoomID = '" & NRoomID & "'")

    Case "Move"
    NX(index) = Split(SData, " ")(1)
    NY(index) = Split(SData, " ")(2)
    StatusOk(index) = False
    
Case "SEARCHBUSYFLATS"
Dim sts As Integer
Dim StartID As String
Dim EndID As Integer
PubRooms = ""
PrivRooms = ""
AmountInPRoom = "0"
AmountOfPubRooms = MySQLQuery("SELECT AmountOfPubRooms FROM system")
    For i = 1 To AmountOfPubRooms
        PubRoomName = MySQLQuery("SELECT RoomName FROM pub_rooms WHERE RoomID = '" & i & "'")
    For b = 1 To Form1.SockI
        If Client(b).InRoom = "Cafe Ole" And PubRoomName = "Cafe Ole" Then
            AmountInPRoom = AmountInPRoom + 1
        Else
                AmountInPRoom = AmountInPRoom
        End If
    MaxinPRoom = MySQLQuery("SELECT MaxIn FROM pub_rooms WHERE RoomID = '" & i & "'")
    Dontknow = MySQLQuery("SELECT DontKnow FROM pub_rooms WHERE RoomID = '" & i & "'")
    PHeightmap = MySQLQuery("SELECT HeightMap FROM pub_rooms WHERE RoomID = '" & i & "'")
    PRoomPart = MySQLQuery("SELECT RoomPart FROM pub_rooms WHERE RoomID = '" & i & "'")
    PubRooms = PubRooms & PubRoomName & "," & AmountInPRoom & "," & MaxinPRoom & ",127.0.0.1/127.0.0.1," & Form1.TxtPort & "," & PubRoomName & vbTab & PHeightmap & "," & AmountInPRoom & "," & MaxinPRoom & "," & RoomPart & Chr(13)
    Next b
    Next i
    
    SendData index, "ALLUNITS " & Chr(13) & PubRooms
    
    StartID = Split(SData, "/")(1)
    StartID = Split(StartID, ",")(0)
    EndID = StartID + 11
        For sts = StartID To EndID
On Error GoTo lusl
        If MySQLExists("SELECT RoomID FROM priv_rooms WHERE RoomID = '" & sts & "'") = True Then
            RoomName = MySQLQuery("SELECT RoomName FROM priv_rooms WHERE RoomID = '" & sts & "'")
            RoomOwner = MySQLQuery("SELECT RoomOwner FROM priv_rooms WHERE RoomID = '" & sts & "'")
            RoomDesc = MySQLQuery("SELECT RoomDesc FROM priv_rooms WHERE RoomID = '" & sts & "'")
            RoomType = MySQLQuery("SELECT RoomStatus FROM priv_rooms WHERE RoomID = '" & sts & "'")
            MaxinRoom = "25"
            PrivRooms = PrivRooms & sts & "/" & RoomName & "/" & RoomOwner & "/" & RoomType & "/ekakerros/floor1/127.0.0.1/127.0.0.1/" & Form1.TxtPort & "/" & GetRoomCount(sts) & "/null/" & RoomDesc & Chr(13)
        End If
lusl:
     Next sts
    SendData index, "BUSY_FLAT_RESULTS " & Chr(13) & PrivRooms
     
Case "TRYFLAT"
Client(index).InRoom = CInt(Split(SData, "/")(1))
SendData index, "FLAT_LETIN "

Case "GOTOFLAT"
Dim ownercheck As String
Dim ab As Integer
Dim RoomID As Integer
Client(index).Figure = GetFigure(Client(index).Name)
Client(index).Mission = GetMission(Client(index).Name)
RoomID = Split(SData, "/")(1)

    SendData index, "ROOM_READY " & Chr(13) & Split(RoomProperties(CStr(Split(SData, "/")(1))), Chr(13))(0) & " " & Replace(Split(RoomProperties(CStr(Split(SData, "/")(1))), Chr(13))(1), Chr(13), "")
    SendData index, "FLATPROPERTY " & Chr(13) & "wallpaper/" & Replace(Split(RoomProperties(CStr(Split(SData, "/")(1))), Chr(13))(2), Chr(13), "")
    SendData index, "FLATPROPERTY " & Chr(13) & "floor/" & Replace(Split(RoomProperties(CStr(Split(SData, "/")(1))), Chr(13))(3), Chr(13), "")
    IsOwner = (Split(RoomProperties(CStr(Split(SData, "/")(1))), Chr(13))(4))
    IsOwner = Right(IsOwner, Len(IsOwner) - 1)
        If Client(index).Name = IsOwner Then
            SendData index, "YOUAREOWNER "
        End If
    SendData index, "HEIGHTMAP " & Chr(13) & Replace(GetRoomHeightmap(CStr(Split(SData, "/")(1))), " ", Chr(13))
    SendData index, "OBJECTS WORLD 0 " & Replace(Split(RoomProperties(CStr(Split(SData, "/")(1))), Chr(13))(1), Chr(13), "")
    temp = ""
        For ab = 1 To Form1.SockI
            If Form1.sckAccept(ab).State = sckConnected And Client(ab).InRoom = Split(SData, "/")(1) Then
                temp = temp & Client(ab).Name & " " & Chr(13) & Client(ab).Figure & GetStartingPos(CStr(Split(SData, "/")(1))) & Chr(10) & Client(index).Mission & Chr(13)
            End If
        Next ab
    Broadcast "USERS " & Chr(13) & temp
    
Case "GETUNITUSERS"
Dim TheROOM As String
    TheROOM = Split(SData, "/")(1)
        Select Case TheROOM

    Case "Habbo Lido"
            MySQLQuery ("UPDATE InRoom FROM users WHERE Username = '" & Client(index).Name & "'")
            SendData index, "UNITMEMBERS "
    
    Case "Cafe Ole"
            SendData index, "UNITUSERS " & Chr(13)
        End Select
        
Case "SEARCHFLATFORUSER"
Dim GetRoomCounts As Integer
Dim o As Integer
Dim z As Integer
Dim zs As Integer
Dim OwnedRoomIDs As String
    GetRoomCounts = MySQLQuery("SELECT RoomCount FROM users WHERE Username = '" & Client(index).Name & "'")
    OwnedRoomIDs = MySQLQuery("SELECT OwnedRoomIDs FROM users WHERE Username = '" & Client(index).Name & "'")
    zs = 1
        For o = 1 To GetRoomCounts
    z = Split(OwnedRoomIDs, ";")(zs)
    RoomName = MySQLQuery("SELECT RoomName FROM priv_rooms WHERE RoomID = '" & z & "'")
    RoomOwner = MySQLQuery("SELECT RoomOwner FROM priv_rooms WHERE RoomID = '" & z & "'")
    MaxinRoom = MySQLQuery("SELECT MaxInRoom FROM priv_rooms WHERE RoomID = '" & z & "'")
    RoomDesc = MySQLQuery("SELECT RoomDesc FROM priv_rooms WHERE RoomID = '" & z & "'")
    RoomType = MySQLQuery("SELECT RoomStatus FROM priv_rooms WHERE RoomID = '" & z & "'")
    OwnRooms = OwnRooms & zs & "/" & RoomName & "/" & RoomOwner & "/" & RoomType & "/ekakerros/floor1/127.0.0.1/127.0.0.1/" & Form1.TxtPort & "/" & GetRoomCount(z) & "/null/" & RoomDesc & Chr(13)
    zs = zs + 1
        Next o
    SendData index, "BUSY_FLAT_RESULTS 1" & Chr(13) & OwnRooms
    
Case "GOAWAY"
    NX(index) = "3"
    NY(index) = "5"
    StatusOk(index) = False
    CloseSock (index)
    
Case "SEARCHFLAT"
    Dim Flatname As String
        Flatname = Split(SData, "%")(1)
        GetRoomCounts = MySQLQuery("SELECT RoomCount FROM users WHERE Username = '" & Flatname & "'")
        OwnedRoomIDs = MySQLQuery("SELECT OwnedRoomIDs FROM users WHERE Username = '" & Flatname & "'")
        zs = 1
            For o = 1 To GetRoomCounts
                z = Split(OwnedRoomIDs, ";")(zs)
                RoomName = MySQLQuery("SELECT RoomName FROM priv_rooms WHERE RoomID = '" & z & "'")
                RoomOwner = MySQLQuery("SELECT RoomOwner FROM priv_rooms WHERE RoomID = '" & z & "'")
                MaxinRoom = MySQLQuery("SELECT MaxInRoom FROM priv_rooms WHERE RoomID = '" & z & "'")
                RoomDesc = MySQLQuery("SELECT RoomDesc FROM priv_rooms WHERE RoomID = '" & z & "'")
                RoomType = MySQLQuery("SELECT RoomStatus FROM priv_rooms WHERE RoomID = '" & z & "'")
                OwnRooms = OwnRooms & zs & "/" & RoomName & "/" & RoomOwner & "/" & RoomType & "/ekakerros/floor1/127.0.0.1/127.0.0.1/" & Form1.TxtPort & "/" & GetRoomCount(z) & "/null/" & RoomDesc & Chr(13)
                zs = zs + 1
            Next o
            SendData index, "BUSY_FLAT_RESULTS 1" & Chr(13) & OwnRooms
    
Case "CHAT"
Dim tempchat As String
        tempchat = Mid(SData, InStr(SData, " ") + 1)
        If Left(tempchat, 8) = ":inject " Then
            If IsAdmin(Client(index).Name) = True Then
                tempchat = Mid(tempchat, InStr(tempchat, " ") + 1)
                tempchat = Replace(tempchat, "$13", Chr(13))
                tempchat = Replace(tempchat, "$9", Chr(9))
                SendData index, tempchat
                Broadcast "CHAT " & Chr(13) & Client(index).Name & " [Data Injected]"
                Exit Function
            Else
                SendData index, "CHAT " & Chr(13) & Client(index).Name & " Only Administrators Can Use This Function"
            End If
        
        ElseIf Left(tempchat, 11) = ":Broadcast " Then
            If IsAdmin(Client(index).Name) = True Then
                tempchat = Mid(tempchat, InStr(tempchat, " ") + 1)
                tempchat = Replace(tempchat, "$13", Chr(13))
                tempchat = Replace(tempchat, "$9", Chr(9))
                Broadcast tempchat
                Broadcast "CHAT " & Chr(13) & Client(index).Name & " [Data Broadcast Injected]"
                Exit Function
            Else
                SendData index, "CHAT " & Chr(13) & Client(index).Name & " Only Administrators Can Use This Function"
            End If
    
    ElseIf Left(tempchat, 6) = ":kick " Then
            If IsAdmin(Client(index).Name) = True Then
                tempchat = Mid(tempchat, InStr(tempchat, " ") + 1)
                Broadcast "CHAT " & Chr(13) & Client(index).Name & " [User Kicked]"
                Broadcast "LOGOUT " & Chr(13) & tempchat
                Exit Function
            Else
                SendData index, "CHAT " & Chr(13) & Client(index).Name & " Only Administrators Can Use This Function"
            End If
            
     ElseIf Left(tempchat, 7) = ":alert " Then
            If IsAdmin(Client(index).Name) = True Then
                tempchat = Mid(tempchat, InStr(tempchat, " ") + 1)
                Dim alertindex As Integer
                Dim alertmessage As String
                Dim alertname As String
                'alertindex = 0
                alertmessage = Split(tempchat, ";")(1)
                alertname = Split(tempchat, ";")(0)
                If LCase(alertname) = "all" Then
                    Broadcast "SYSTEMBroadcast " & Chr(13) & "Alert sent by Hotel Staff: " & alertmessage
                    SendData index, "CHAT " & Chr(13) & Client(index).Name & " [Alert Sent to: Everyone]"
                    Exit Function
                Else
                    For alertindexfind = 0 To Form1.SockI
                        If Username(alertindexfind) = alertname Then
                            alertindex = alertindexfind
                        End If
                    Next
                    SendData alertindex, "SYSTEMBroadcast " & Chr(13) & " " & alertmessage
                    SendData index, "CHAT " & Chr(13) & Client(index).Name & " [Alert Sent to: " & alertname & "]"
                    Exit Function
                End If
            Else
                SendData index, "CHAT " & Chr(13) & Client(index).Name & " Only Administrators Can Use This Function"
            End If

        ElseIf Left(tempchat, 9) = ":whisper " Then
            tempchat = Mid(tempchat, InStr(tempchat, " ") + 1)
            Dim whispermessage As String
            Dim whispername As String
            Dim whisperindex As Integer
            whisperindex = 99
            'whisperindex = 0
            whispermessage = Split(tempchat, ";")(1)
            whispername = Split(tempchat, ";")(0)
            For whisperindexfind = 0 To Form1.SockI
                If Username(whisperindexfind) = whispername Then
                    whisperindex = whisperindexfind
                End If
            Next
            SendData whisperindex, "WHISPER " & Chr(13) & Client(index).Name & " " & whispermessage
            SendData index, "WHISPER " & Chr(13) & Client(index).Name & " " & whispermessage
            Exit Function

' Custom-made function
        ElseIf Left(tempchat, 6) = ":wave " Then
            tempchat = Mid(tempchat, InStr(tempchat, " ") + 1)
            If tempchat = "on" Then
            status(index) = status(index) & "/wave/"
            StatusOk(index) = False
            Exit Function
            ElseIf tempchat = "off" Then
            status(index) = Replace(status(index), "/wave/", "")
            StatusOk(index) = False
            Exit Function
            End If
            
        ' Custom-made function
        ElseIf Left(tempchat, 5) = ":lay " Then
            tempchat = Mid(tempchat, InStr(tempchat, " ") + 1)
            If tempchat = "on" Then
            status(index) = status(index) & "/lay 1/"
            StatusOk(index) = False
            Exit Function
            ElseIf tempchat = "off" Then
            status(index) = Replace(status(index), "/lay 1/", "")
            StatusOk(index) = False
            Exit Function
            End If
            
        ' Custom-made function
        ElseIf Left(tempchat, 5) = ":sit " Then
            tempchat = Mid(tempchat, InStr(tempchat, " ") + 1)
            If tempchat = "on" Then
            status(index) = status(index) & "/sit 1/"
            StatusOk(index) = False
            Exit Function
            ElseIf tempchat = "off" Then
            status(index) = Replace(status(index), "/sit 1/", "")
            StatusOk(index) = False
            Exit Function
            End If
            
        
        End If
        
        Broadcast "CHAT " & Chr(13) & Client(index).Name & " " & tempchat
        status(index) = status(index) & "/talk/"
        StatusOk(index) = False
        Form1.tmrTalk(index).Interval = Len(tempchat) * 150
        Form1.tmrTalk(index).Enabled = True
        StatusOk(index) = False

                
 Case "SHOUT"
 Dim tempchat2 As String
        tempchat2 = Mid(SData, InStr(SData, " "))
                tempchat2 = Mid(tempchat2, InStr(tempchat2, " "))
                tempchat2 = Replace(tempchat2, "$13", Chr(13))
                tempchat2 = Replace(tempchat2, "$9", Chr(9))
                SendData index, tempchat2
                Broadcast "SHOUT " & Chr(13) & Client(index).Name & " " & tempchat2
                status(index) = status(index) & "/talk/"
                StatusOk(index) = False
                Form1.tmrTalk(index).Interval = Len(tempchat2) * 150
                Form1.tmrTalk(index).Enabled = True
                StatusOk(index) = False
                
Case "GETSTRIP"
Dim strip As String
Dim za As Integer
Dim zas As Integer
Dim GetFurniCount As Integer
Dim handitems As String
    GetFurniCount = MySQLQuery("SELECT FurnitureCount FROM system")
    OwnedFurnitureID = MySQLQuery("SELECT OwnedFurnitureID FROM users WHERE Username = '" & Client(index).Name & "'")
    zas = 1
        For o = 1 To GetFurniCount
            za = Split(OwnedFurnitureID, ";")(zas)
            Name = MySQLQuery("SELECT name from hand_items where id = '" & za & "'")
            sprite = MySQLQuery("SELECT sprite from hand_items where id = '" & za & "'")
            details = MySQLQuery("SELECT details from hand_items where id = '" & za & "'")
            colour = MySQLQuery("SELECT colour from hand_items where id = '" & za & "'")
            handitems = handitems & "BLSI;" & za & ";0;S;" & za & ";" & sprite & ";" & Name & ";" & details & ";1;1;" & colour & "/" & Chr(13)
            zas = zas + 1
        Next o
        SendData index, "STRIPINFO " & Chr(13) & handitems

    
Case "Dance"
    status(index) = Replace(status(index), "dance/", "")
    status(index) = status(index) & "dance/"
    StatusOk(index) = False
    Broadcast status(index)
        
Case "LOOKTO"
   LooktoX = Split(theCmd, " ")(1)
   LooktoY = Split(theCmd, " ")(2)
   LookTo = True
   StatusOk(index) = False

Case "STATUSOK"
   SendData index, "OK "
   
Case "STOP"
    If Split(SData, " ")(1) = "Dance" Then
        status(index) = Replace(status(index), "dance/", "")
        StatusOk(index) = False
    ElseIf Split(SData, " ")(1) = "Moderator" Then
       status(index) = Replace(status(index), "mod " & Badgetype(Client(index).Name) & "/", "")
       StatusOk(index) = False
    End If
    
Case "Moderator"
    If Split(SData, " ")(1) = MiscFunctions.Badgetype(Client(index).Name) Then
            If IsAdmin(Client(index).Name) = True Then
                status(index) = status(index) & "mod " & Badgetype(Client(index).Name) & "/"
                StatusOk(index) = False
            End If
    End If
    

End Select
End Function
Public Function Broadcast(data As String)
If Form1.ChkServer.Value = 1 Then
DebugText "Broadcast: " & ": " & data
End If
    Dim x As Integer
    For x = 1 To SockI
        If Form1.sckAccept(x).State = 7 Then
            Form1.sckAccept(x).SendData "# " & data & vpData("13 35 35")
            DoEvents
        End If
    Next
End Function
Public Function SendData(x As Integer, data As String)
If Form1.ChkServer.Value = 1 Then
DebugText "Server Sent " & x & " : " & data
End If
        If Form1.sckAccept(x).State = 7 Then
            Form1.sckAccept(x).SendData "# " & data & vpData("13 35 35")
        End If
End Function
Public Function ToMods(data As String)
    Dim x As Integer
    For x = 1 To MaxCon
        If frmMain.sckAccept(x).State = 7 Then
            If IsAdmin(Username(x)) = True Then
                Form1.sckAccept(x).SendData "# " & data & Chr(13) & "##"
                DoEvents
            End If
        End If
    Next
   ' DebugText "Mod Broadcast: " & ": " & data
End Function
Public Function NewKey() As String
NewKey = "nz3vlinucwjwy4o66zznyolynl6b2pw1uhz8vj3ptwqdolmypmt0oinjqdkpl1xd69tyi9d0ahzviuww46znoylbp1h8jpwdlym0ijdp1d9y90h"
End Function

