Blank517 Posted August 26, 2016 Share Posted August 26, 2016 Hi, when a client sends /logout to the server i want that the server find the id of the client and set his online status to 0 Using 'default' I have no problems, but when I do this with 'blank517' gives me id 10 and then for the database remains online Database while Blank517 logout: id | username | password | permissions | online | 0 | default | pass1 | 0 | 0 | 1 | Blank517 | pass | 0 | 1 | Server recv: Func _Recv_From_Sockets_() For $0 = 1 To $max_connections $Recv = TCPRecv ($Socket_Data[$0][0],1024) If StringLeft($Recv, 1) = "/" Then If StringInStr($Recv, "logout") Then _SQLite_Query(-1, "SELECT id FROM Users WHERE username = '" & $Socket_Data[$0][1] & "' AND online = '1';", $hQuery) While _SQLite_FetchData($hQuery, $aRow) = $SQLITE_OK $sMsg &= $aRow[0]; <-- $sMsg = 10 after FetchData WEnd _SQLite_Exec(-1, "UPDATE Users SET online = '0' WHERE id = '" & $sMsg & "';") For $000 = 1 To $max_connections TCPSend($Socket_Data[$000][0], $Socket_Data[$0][1] & " ha effettuato il logout") Next TCPCloseSocket($Socket_Data[$0][0]) $sMsg = Null EndIf Else _Broadcast_To_Sockets_ ($Recv) EndIf Next EndFunc *excuse me for my bad english * Link to comment Share on other sites More sharing options...
AutoBert Posted August 26, 2016 Share Posted August 26, 2016 run this func: Func _Recv_From_Sockets_() For $0 = 1 To $max_connections $Recv = TCPRecv ($Socket_Data[$0][0],1024) If StringLeft($Recv, 1) = "/" Then If StringInStr($Recv, "logout") Then _SQLite_Query(-1, "SELECT id FROM Users WHERE username = '" & $Socket_Data[$0][1] & "' AND online = '1';", $hQuery) While _SQLite_FetchData($hQuery, $aRow) = $SQLITE_OK $sMsg &= $aRow[0]; <-- $sMsg = 10 after FetchData WEnd $sMsg=StringStripWS($sMsg,3) ConsoleWrite($sMsg&@CRLF) _SQLite_Exec(-1, "UPDATE Users SET online = '0' WHERE id = '" & $sMsg & "';") For $000 = 1 To $max_connections TCPSend($Socket_Data[$000][0], $Socket_Data[$0][1] & " ha effettuato il logout") Next TCPCloseSocket($Socket_Data[$0][0]) $sMsg = Null EndIf Else _Broadcast_To_Sockets_ ($Recv) EndIf Next EndFunc and post the output of the console. Link to comment Share on other sites More sharing options...
Blank517 Posted August 26, 2016 Author Share Posted August 26, 2016 The output is 11 Link to comment Share on other sites More sharing options...
AutoBert Posted August 26, 2016 Share Posted August 26, 2016 So all records with id=11 will be set to offline. Link to comment Share on other sites More sharing options...
Blank517 Posted August 26, 2016 Author Share Posted August 26, 2016 Just now, AutoBert said: So all records with id=11 will be set to offline. Ok, but 'Blank517' has id '1' not '11' Link to comment Share on other sites More sharing options...
AutoBert Posted August 26, 2016 Share Posted August 26, 2016 11 minutes ago, Blank517 said: Ok, but 'Blank517' has id '1' not '11' Then are 2 records found and '1'&'1' = '11' so test this: Func _Recv_From_Sockets_() For $0 = 1 To $max_connections $Recv = TCPRecv ($Socket_Data[$0][0],1024) If StringLeft($Recv, 1) = "/" Then If StringInStr($Recv, "logout") Then _SQLite_Query(-1, "SELECT id FROM Users WHERE username = '" & $Socket_Data[$0][1] & "' AND online = '1';", $hQuery) If _SQLite_FetchData($hQuery, $aRow) = $SQLITE_OK Then $sMsg &= $aRow[0]; <-- $sMsg = 10 after FetchData $sMsg=StringStripWS($sMsg,3) ;test if needed ConsoleWrite($sMsg&@CRLF) _SQLite_Exec(-1, "UPDATE Users SET online = '0' WHERE id = '" & $sMsg & "';") EndIf For $000 = 1 To $max_connections TCPSend($Socket_Data[$000][0], $Socket_Data[$0][1] & " ha effettuato il logout") Next TCPCloseSocket($Socket_Data[$0][0]) $sMsg = Null EndIf Else _Broadcast_To_Sockets_ ($Recv) EndIf Next EndFunc Link to comment Share on other sites More sharing options...
Blank517 Posted August 26, 2016 Author Share Posted August 26, 2016 Thanks, now it works ^^ Link to comment Share on other sites More sharing options...
Blank517 Posted August 26, 2016 Author Share Posted August 26, 2016 Last help for sqlite xP When a user login, even if it is not registered and therefore hasn't an id, the server accepts the connection _SQLite_Query(-1, "SELECT id FROM Users WHERE username = '" & $Socket_Data[$0][1] & "' AND password = '" & $Socket_Data[$0][2] & "' AND online = 0;", $hQuery) If _SQLite_FetchData($hQuery, $aRow) = $SQLITE_OK Then $sMsg &= $aRow[0] EndIf If $sMsg = "" Then ConsoleWrite("[Alert] Connection refused! (" & $Socket_Data[$0][1] & ")") TCPSend($Socket_Data[$0][0], "Connection refused!" & @CRLF & "There is a problem with the database:" & @CRLF & " - You're not registered" & @CRLF & " - You're already online") TCPCloseSocket($Socket_Data[$0][0]) Return EndIf Link to comment Share on other sites More sharing options...
kylomas Posted August 26, 2016 Share Posted August 26, 2016 Blank517, You are concatenating the query results to the variable $msg...try just setting $msg to the results of the query. ...on a smart phone so cant test and typing is atrocious... Kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Blank517 Posted August 26, 2016 Author Share Posted August 26, 2016 25 minutes ago, kylomas said: You are concatenating the query results to the variable $msg...try just setting $msg to the results of the query. The result does not change it always give me a null id Link to comment Share on other sites More sharing options...
kylomas Posted August 26, 2016 Share Posted August 26, 2016 (edited) Blank517, Are you using a DB shell to interrogate/develop your DB? SqliteExpert is an excellent tool if you need one. And it has a free version. If you do have a DB viewer/shell, verify that ID contains what you think it should. Also, it does not make sense that you are getting a "11" from fetchdata (post #3). I'm not sure that problem has been identified yet. Can you supply a reproducer, DB schema? kylomas edit: or your entire script? Edited August 26, 2016 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Blank517 Posted August 27, 2016 Author Share Posted August 27, 2016 Server Chat sqlite admin.7z Link to comment Share on other sites More sharing options...
Blank517 Posted August 27, 2016 Author Share Posted August 27, 2016 16 hours ago, kylomas said: Blank517, You are concatenating the query results to the variable $msg...try just setting $msg to the results of the query. ...on a smart phone so cant test and typing is atrocious... Kylomas 16 hours ago, Blank517 said: The result does not change it always give me a null id Solved _SQLite_Query(-1, "SELECT id FROM Users WHERE username = '" & $Recv[1] & "' AND password = '" & $Recv[2] & "' AND online = 0;", $hQuery) If _SQLite_FetchData($hQuery, $aRow) = $SQLITE_OK Then $sMsg = $aRow[0] EndIf If $sMsg = Null Then; <-- not $sMsg = "" but = Null ConsoleWrite("[Alert] Connection refused! (" & $Recv[1] & ")") TCPSend($Socket_Data[$0][0], "Connection refused!" & @CRLF & "There is a problem with the database:" & @CRLF & " - You're not registered" & @CRLF & " - You're already online") TCPCloseSocket($Socket_Data[$0][0]) Return EndIf Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now