Public Sub Client1_MessageArrived (Topic As String, Payload() As Byte)
Dim cp As ConnectionPool
Dim sql2 As JdbcSQL
' Initialize Bothe rConnection pool and SQL
If cp.IsInitialized = False Then 'in case the connection closes
cp.Initialize("com.mysql.jdbc.Driver", "jdbc:mysql://192.168.1.103:3306/*****_quiz", "user", "**********")
End If
sql2 = cp.GetConnection
Dim PayLoadStr As String
Log("Message Arrived")
Log("Message Topic "&Topic)
Log(Payload.Length)
PayLoadStr = BytesToString(Payload, 0, Payload.Length, "utf8")
Log(Topic & " = " & PayLoadStr)
If PayLoadStr.Length = 0 Then
Return
End If
Dim paytopic As String
paytopic=Topic.Trim
Log("This should be right "&paytopic)
Select Topic
Case "Server" 'Received the initial Logingname of the user to create a perm topic retained
Main.LIncomingMessage.Text=Topic&" "&PayLoadStr
If PayLoadStr <> "" Then
Subscribe2(PayLoadStr.Trim&"/Register",2)
Main.Member=PayLoadStr.Trim
Main.UpdateCat
Main.UpdateSubCat
End If
Case "Server/Adinfo" ' Saves When the Advert Was displayed as well as the user and the duration
Dim arrNumString() As String =Regex.Split(",",PayLoadStr )
sql2.ExecNonQuery2("INSERT INTO advertinfo VALUES (?,?,?,?)", Array As Object(arrNumString(0),arrNumString(1),arrNumString(2),arrNumString(3)))
sql2.Close
cp.ClosePool
Case "Server/Advert" 'Sends the Advert Website Address
Dim arrNumString() As String =Regex.Split(",",PayLoadStr )
Log("record to retrieve "&arrNumString(0))
Dim adv As Int = arrNumString(0)
Dim Cursor As JdbcResultSet
Cursor = sql2.ExecQuery2("SELECT AdNumber, WebsiteAddr FROM adverts where AdNumber =?", Array As String(adv))
Do While Cursor.NextRow
Log("about to get Ad")
Dim sendstr As String =Cursor.GetString("WebsiteAddr")
Log(sendstr)
PostThis2(arrNumString(1)&"/Adverts",sendstr,2,False)
Loop
Cursor.Close
sql2.Close
cp.ClosePool
Case "Server/Reg" ' Registers a player on the system
Log("Received reg message")
Log(PayLoadStr.Trim)
sql2 = cp.GetConnection
Dim arrNumString() As String =Regex.Split(",",PayLoadStr )
sql2.ExecNonQuery2("INSERT INTO user_db VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)", Array As Object(arrNumString(12),arrNumString(0), arrNumString(1), arrNumString(2), arrNumString(3), arrNumString(4), arrNumString(5), arrNumString(6), arrNumString(7), arrNumString(8), arrNumString(9), arrNumString(10), arrNumString(11)))
Log("past insert local")
sql2.Close
cp.ClosePool
End Select
DateTime.SetTimeZone(2)
End Sub