Very confused
- zachofthegolden1
- Posts: 89
- Joined: 05 Sep 2011, 19:31
Very confused
Hello, I'm very confused, Ive setup a database so it logs in the database and it registers but when you login the mod='0' doesn't show up so my admin options for moderators will not show. is there a way i could make ismoderator a coloum in my database and smarfox can read it and do my actions
Please note i've used search and google and i dont get anyhing. The only thing that keeps poping up is freelancer.com, freelancer.ca etc
Please note i've used search and google and i dont get anyhing. The only thing that keeps poping up is freelancer.com, freelancer.ca etc
-ZG1
Hi.
If you want to set an user moderator depending on a value on the database, you have to do some work on the server-side extension that handles the login.
After you check that the user is registered and after he logs in, you just have to do a simple thing (on the server side):
where mod is the value retrieved from the database.
If you want to set an user moderator depending on a value on the database, you have to do some work on the server-side extension that handles the login.
After you check that the user is registered and after he logs in, you just have to do a simple thing (on the server side):
Code: Select all
if(mod == 1){
user.setAsModerator(true);
}
where mod is the value retrieved from the database.
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
- zachofthegolden1
- Posts: 89
- Joined: 05 Sep 2011, 19:31
I used the extention profided in your tutoial on your website
Code: Select all
/*
-------------------------------------------------------------------
| Database Login Tutorial |
| |
| Made by |
| Rjgtav |
| |
| For more tutorials and tips of SmartFoxServer please visit: |
| http://sfs-tutor.blogspot.com/ |
| |
-------------------------------------------------------------------
*/
var dbase
var userName;
var passWord;
var SocketChannel;
function init(){
dbase = _server.getDatabaseManager()
}
function destroy(){
delete dbase
delete userName;
delete passWord;
delete SocketChannel;
}
function handleInternalEvent(evt)
{
trace(evt)
if(evt.name == "loginRequest"){
var error = "";
userName = evt["nick"];//It could be evt.nick
passWord = evt["pass"];//It could be evt.pass
SocketChannel = evt["chan"];//It could be evt.chan
var sql = "SELECT COUNT(USERNAME) FROM mmousers WHERE USERNAME='"+userName+"' AND PASSWORD='"+passWord+"'";
var queryRes = dbase.executeQuery(sql)
var response = {}
if (queryRes != null){
var Row = queryRes.get(0)
var count = Row.getItem("COUNT(USERNAME)");
if(count == 1){
trace("SUCCESSFULL LOGIN")
var obj = _server.loginUser(userName, passWord, SocketChannel)
if(obj.success){
response._cmd = "logOK";
response.name = userName;
}else{
error = obj.error;
response._cmd = "logKO";
}
}else if(count == 0){
trace("FAILED LOGIN")
response._cmd = "logKO";
error = "Wrong username or password";
}
}else{
response._cmd = "logKO";
error = "Error connecting to the database"
}
response.error = error;
_server.sendResponse(response, -1, null, SocketChannel)
}
}
-ZG1
So you just need to change the SQL code so it Selects the row (if match was found) instead of counting the number of matched accounts, and then, after the login, you do something like:
I suggest you to check and read the Serverside ActionScript API, as it has lots of examples for each of the server features:
http://www.smartfoxserver.com/docs/docP ... /index.htm
Code: Select all
if(obj.success){
response._cmd = "logOK";
response.name = userName;
if(Row.getItem("MODERATOR") == 1){
var user = _server.getUserByChannel(SocketChannel);
user.setAsModerator(true);
}
}else{
...
I suggest you to check and read the Serverside ActionScript API, as it has lots of examples for each of the server features:
http://www.smartfoxserver.com/docs/docP ... /index.htm
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
- zachofthegolden1
- Posts: 89
- Joined: 05 Sep 2011, 19:31
- zachofthegolden1
- Posts: 89
- Joined: 05 Sep 2011, 19:31
What error? Client-side or Server-Side? And what is that window supposed to do?
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
- zachofthegolden1
- Posts: 89
- Joined: 05 Sep 2011, 19:31
I'm sorry but if you don't provide more info we can't help you much. I suggest you to start by debugging your extension. Add some traces at each step so you can find where the error is. Probably the error is on the SQL execution. If so, there must be an explicit error on the server-side.
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
- zachofthegolden1
- Posts: 89
- Joined: 05 Sep 2011, 19:31
this is the modified code
it does nothing when i click login so it sends th elogin request but no responce, if you have time could you use the join me thing again?
Code: Select all
/*
-------------------------------------------------------------------
| Database Login Tutorial |
| |
| Made by |
| Rjgtav |
| |
| For more tutorials and tips of SmartFoxServer please visit: |
| http://sfs-tutor.blogspot.com/ |
| |
-------------------------------------------------------------------
*/
var dbase
var userName;
var passWord;
var SocketChannel;
function init(){
dbase = _server.getDatabaseManager()
}
function destroy(){
delete dbase
delete userName;
delete passWord;
delete SocketChannel;
}
function handleInternalEvent(evt)
{
trace(evt)
if(evt.name == "loginRequest"){
var error = "";
userName = evt["nick"];//It could be evt.nick
passWord = evt["pass"];//It could be evt.pass
SocketChannel = evt["chan"];//It could be evt.chan
var sql = "SELECT COUNT(USERNAME) FROM mmousers WHERE USERNAME='"+userName+"' AND PASSWORD='"+passWord+"'";
var queryRes = dbase.executeQuery(sql)
var response = {}
if (queryRes != null){
var Row = queryRes.get(0)
var count = Row.getItem("COUNT(USERNAME)");
if(count == 1){
trace("SUCCESSFULL LOGIN")
var obj = _server.loginUser(userName, passWord, SocketChannel)
if(obj.success){
response._cmd = "logOK";
response.name = userName;
if(Row.getItem("MODERATOR") == 1){
var user = _server.getUserByChannel(SocketChannel);
user.setAsModerator(true);
}else{
error = obj.error;
response._cmd = "logKO";
}
}else if(count == 0){
trace("FAILED LOGIN")
response._cmd = "logKO";
error = "Wrong username or password";
}
}else{
response._cmd = "logKO";
error = "Error connecting to the database"
}
response.error = error;
_server.sendResponse(response, -1, null, SocketChannel)
}
}
-ZG1
- zachofthegolden1
- Posts: 89
- Joined: 05 Sep 2011, 19:31
Re: Very confused
I'm still having the issue i have added the codes in as follows
This is the server side database login extension
But the problem is i the mod_level is a value in my database fr any user and i wish for it to be if mod level = 1 in the database it will set th user as a moderator on the client side so the moderators can use the options ive set for moderators. also this is my responce coding
It lets the users login but just completely ignores the mod level option
This is the server side database login extension
Code: Select all
var dbase
var userName;
var passWord;
var SocketChannel;
function init(){
dbase = _server.getDatabaseManager()
}
function destroy(){
delete dbase
delete userName;
delete passWord;
delete SocketChannel;
}
function handleInternalEvent(evt)
{
if(evt.name == "loginRequest"){
var error = "";
userName = evt["nick"];
passWord = evt["pass"];
SocketChannel = evt["chan"];
var sql = "SELECT COUNT(username) FROM users WHERE username='"+userName+"' AND password='"+passWord+"'";
var queryRes = dbase.executeQuery(sql)
var response = {}
if (queryRes != null){
var Row = queryRes.get(0)
var count = Row.getItem("COUNT(username)");
if(count == 1){
trace("SUCCESSFULL LOGIN")
var obj = _server.loginUser(userName, passWord, SocketChannel)
if(obj.success){
response._cmd = "logOK";
response.name = userName;
if(Row.getItem("mod_level") == 1){
var user = _server.getUserByChannel(SocketChannel);
user.setAsModerator(true);
}
}else{
error = obj.error;
response._cmd = "logKO";
}
}else if(count == 0){
trace("FAILED LOGIN")
response._cmd = "logKO";
error = "Wrong username or password";
}
}else{
response._cmd = "logKO";
error = "Error connecting to the database"
}
response.error = error;
_server.sendResponse(response, -1, null, SocketChannel)
}
}
But the problem is i the mod_level is a value in my database fr any user and i wish for it to be if mod level = 1 in the database it will set th user as a moderator on the client side so the moderators can use the options ive set for moderators. also this is my responce coding
Code: Select all
[Sending]: <msg t='sys'><body action='login' r='0'><login z='dbZone'><nick><![CDATA[test2]]></nick><pword><![CDATA[test2]]></pword></login></body></msg>
[Received]: <msg t="xt"><body action="xtRes" r="-1"><dataObj><var n='error' t='s'></var><var n='name' t='s'>test2</var><var n='_cmd' t='s'>logOK</var></dataObj></body></msg>
It lets the users login but just completely ignores the mod level option
-ZG1
Re: Very confused
Are you sure that the user is really set as Moderator? Try adding a trace before the line where you set the user as moderator, then check on the logs if that message is really shown.
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
- zachofthegolden1
- Posts: 89
- Joined: 05 Sep 2011, 19:31
Re: Very confused
Code: Select all
[DatabaseLoginExt.as]: SUCCESSFULL LOGIN
[DatabaseLoginExt.as]: mod level
[dbExtension.as]: Event received: userJoin
[simpleExt.as]: Event received: userJoin23:16:00.566 - [ WARNING ] > Exception i
n ExtensionHandler: java.lang.NullPointerException
Exception type: java.lang.NullPointerException
java.lang.NullPointerException
at it.gotoandplay.smartfoxserver.controllers.ExtensionHandler.processEve
nt(ExtensionHandler.java:442)
at it.gotoandplay.smartfoxserver.controllers.ExtensionHandler.run(Extens
ionHandler.java:344)
at java.lang.Thread.run(Thread.java:619)
this is extention
Code: Select all
var dbase
var userName;
var passWord;
var SocketChannel;
function init(){
dbase = _server.getDatabaseManager()
}
function destroy(){
delete dbase
delete userName;
delete passWord;
delete SocketChannel;
}
function handleInternalEvent(evt)
{
if(evt.name == "loginRequest"){
var error = "";
userName = evt["nick"];
passWord = evt["pass"];
SocketChannel = evt["chan"];
var sql = "SELECT COUNT(username) FROM users WHERE username='"+userName+"' AND password='"+passWord+"'";
var queryRes = dbase.executeQuery(sql)
var response = {}
if (queryRes != null){
var Row = queryRes.get(0)
var count = Row.getItem("COUNT(username)");
if(count == 1){
trace("SUCCESSFULL LOGIN")
var obj = _server.loginUser(userName, passWord, SocketChannel)
if(obj.success){
response._cmd = "logOK";
response.name = userName;
trace("mod level")
if(Row.getItem("mod_level") == 1){
var user = _server.getUserByChannel(SocketChannel);
trace("mod set")
user.setAsModerator(true);
}
}else{
error = obj.error;
response._cmd = "logKO";
}
}else if(count == 0){
trace("FAILED LOGIN")
response._cmd = "logKO";
error = "Wrong username or password";
}
}else{
response._cmd = "logKO";
error = "Error connecting to the database"
}
response.error = error;
_server.sendResponse(response, -1, null, SocketChannel)
}
}
-ZG1
Re: Very confused
On the AdminTool, does it say that the user truly is a moderator?
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
- zachofthegolden1
- Posts: 89
- Joined: 05 Sep 2011, 19:31
Re: Very confused
rjgtav wrote:On the AdminTool, does it say that the user truly is a moderator?
nope moderator = false. would you be ale to do a join me link so you are able to see my screen? This is just a request if you do have enough time
-ZG1
Return to “SmartFoxServer 1.x Discussions and Help”
Who is online
Users browsing this forum: No registered users and 48 guests